mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): filter out interactive targets when pressing space on canvas tab
Improve input filtering for better accessibility
This commit is contained in:
parent
30e11b4b42
commit
4477e04d59
@ -1,5 +1,4 @@
|
|||||||
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
import { isInputElement } from 'common/util/isInputElement';
|
|
||||||
import {
|
import {
|
||||||
$canvasStage,
|
$canvasStage,
|
||||||
$tool,
|
$tool,
|
||||||
@ -14,6 +13,7 @@ import {
|
|||||||
setShouldShowBoundingBox,
|
setShouldShowBoundingBox,
|
||||||
setShouldSnapToGrid,
|
setShouldSnapToGrid,
|
||||||
} from 'features/canvas/store/canvasSlice';
|
} from 'features/canvas/store/canvasSlice';
|
||||||
|
import { isInteractiveTarget } from 'features/canvas/util/isInteractiveTarget';
|
||||||
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
import { activeTabNameSelector } from 'features/ui/store/uiSelectors';
|
||||||
import { useCallback, useEffect } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { useHotkeys } from 'react-hotkeys-hook';
|
import { useHotkeys } from 'react-hotkeys-hook';
|
||||||
@ -93,7 +93,7 @@ const useInpaintingCanvasHotkeys = () => {
|
|||||||
|
|
||||||
const onKeyDown = useCallback(
|
const onKeyDown = useCallback(
|
||||||
(e: KeyboardEvent) => {
|
(e: KeyboardEvent) => {
|
||||||
if (e.repeat || e.key !== ' ' || isInputElement(e.target as HTMLElement) || activeTabName !== 'unifiedCanvas') {
|
if (e.repeat || e.key !== ' ' || isInteractiveTarget(e.target) || activeTabName !== 'unifiedCanvas') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($toolStash.get() || $tool.get() === 'move') {
|
if ($toolStash.get() || $tool.get() === 'move') {
|
||||||
@ -108,7 +108,7 @@ const useInpaintingCanvasHotkeys = () => {
|
|||||||
);
|
);
|
||||||
const onKeyUp = useCallback(
|
const onKeyUp = useCallback(
|
||||||
(e: KeyboardEvent) => {
|
(e: KeyboardEvent) => {
|
||||||
if (e.repeat || e.key !== ' ' || isInputElement(e.target as HTMLElement) || activeTabName !== 'unifiedCanvas') {
|
if (e.repeat || e.key !== ' ' || isInteractiveTarget(e.target) || activeTabName !== 'unifiedCanvas') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!$toolStash.get() || $tool.get() !== 'move') {
|
if (!$toolStash.get() || $tool.get() !== 'move') {
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
import { isInputElement } from 'common/util/isInputElement';
|
||||||
|
|
||||||
|
export const isInteractiveTarget = (target: EventTarget | null) => {
|
||||||
|
if (target instanceof HTMLElement) {
|
||||||
|
return (
|
||||||
|
target.tabIndex > -1 ||
|
||||||
|
isInputElement(target) ||
|
||||||
|
['dialog', 'alertdialog'].includes(target.getAttribute('role') ?? '')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user