Skip to content

Commit e1acb63

Browse files
joshistoastlstein
andauthored
fix(ui): 🐛 HotkeysModal and SettingsModal initial focus (#8687)
* fix(ui): 🐛 `HotkeysModal` and `SettingsModal` initial focus instead of using the `initialFocusRef` prop, the `Modal` component was focusing on the last available Button. This is a workaround that uses `tabIndex` instead which seems to be working. Closes #8685 * style: 🚨 satisfy linter --------- Co-authored-by: Lincoln Stein <[email protected]>
1 parent ab6b672 commit e1acb63

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

invokeai/frontend/web/src/features/system/components/HotkeysModal/HotkeysModal.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useHotkeyData } from 'features/system/components/HotkeysModal/useHotkey
2323
import { StickyScrollable } from 'features/system/components/StickyScrollable';
2424
import { allHotkeysReset } from 'features/system/store/hotkeysSlice';
2525
import type { ChangeEventHandler, ReactElement } from 'react';
26-
import { cloneElement, Fragment, memo, useCallback, useMemo, useRef, useState } from 'react';
26+
import { cloneElement, Fragment, memo, useCallback, useMemo, useState } from 'react';
2727
import { useTranslation } from 'react-i18next';
2828
import { PiXBold } from 'react-icons/pi';
2929

@@ -45,7 +45,6 @@ const HotkeysModal = ({ children }: HotkeysModalProps) => {
4545
const dispatch = useAppDispatch();
4646
const [hotkeyFilter, setHotkeyFilter] = useState('');
4747
const [isEditMode, setIsEditMode] = useState(false);
48-
const inputRef = useRef<HTMLInputElement | null>(null);
4948
const clearHotkeyFilter = useCallback(() => setHotkeyFilter(''), []);
5049
const onChange = useCallback<ChangeEventHandler<HTMLInputElement>>((e) => setHotkeyFilter(e.target.value), []);
5150
const toggleEditMode = useCallback(() => setIsEditMode((prev) => !prev), []);
@@ -91,14 +90,20 @@ const HotkeysModal = ({ children }: HotkeysModalProps) => {
9190
{cloneElement(children, {
9291
onClick: onOpen,
9392
})}
94-
<Modal isOpen={isOpen} onClose={onClose} isCentered size="2xl" useInert={false} initialFocusRef={inputRef}>
93+
<Modal isOpen={isOpen} onClose={onClose} isCentered size="2xl" useInert={false}>
9594
<ModalOverlay />
9695
<ModalContent maxH="80vh" h="80vh">
9796
<ModalHeader>{t('hotkeys.hotkeys')}</ModalHeader>
9897
<ModalCloseButton />
9998
<ModalBody display="flex" flexDir="column" gap={4}>
10099
<InputGroup>
101-
<Input ref={inputRef} placeholder={t('hotkeys.searchHotkeys')} value={hotkeyFilter} onChange={onChange} />
100+
<Input
101+
autoFocus
102+
placeholder={t('hotkeys.searchHotkeys')}
103+
value={hotkeyFilter}
104+
onChange={onChange}
105+
tabIndex={1}
106+
/>
102107
{hotkeyFilter.length && (
103108
<InputRightElement h="full" pe={2}>
104109
<IconButton

invokeai/frontend/web/src/features/system/components/SettingsModal/SettingsModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const SettingsModal = (props: { children: ReactElement }) => {
171171
<ModalOverlay />
172172
<ModalContent maxH="80vh" h="68rem">
173173
<ModalHeader bg="none">{t('common.settingsLabel')}</ModalHeader>
174-
<ModalCloseButton />
174+
<ModalCloseButton tabIndex={1} />
175175
<ModalBody display="flex" flexDir="column" gap={4}>
176176
<ScrollableContent>
177177
<Flex flexDir="column" gap={4}>

0 commit comments

Comments
 (0)