Skip to content

Commit 25cf11c

Browse files
committed
♿️(frontend) add focus on open to modals
Use autoFocus on primary button when opening modals. Made-with: Cursor
1 parent d1a3519 commit 25cf11c

8 files changed

Lines changed: 23 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ and this project adheres to
3737
- 🚸(backend) sort user search results by proximity with the active user #1802
3838
- 🚸(oidc) ignore case when fallback on email #1880
3939
- ⚡️(CI) optimize Docker Hub workflow #1919
40+
- ♿️(frontend) add focus on open to modals #1948
4041

4142
### Fixed
4243

src/frontend/apps/e2e/__tests__/app-impress/doc-grid-move.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,9 @@ test.describe('Doc grid move', () => {
380380
await verifyDocName(page, titleDoc2);
381381

382382
const docTree = page.getByTestId('doc-tree');
383-
await expect(docTree.getByText(titleDoc1)).toBeVisible();
383+
await expect(docTree.getByText(titleDoc1)).toBeVisible({
384+
timeout: 15000,
385+
});
384386

385387
await cleanup();
386388
});

src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteToolBar/ModalConfirmDownloadUnsafe.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const ModalConfirmDownloadUnsafe = ({
2424
<>
2525
<Button
2626
aria-label={t('Cancel the download')}
27+
autoFocus
2728
variant="secondary"
2829
onClick={() => onClose()}
2930
>

src/frontend/apps/impress/src/features/docs/doc-export/components/ModalExport.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
203203
aria-label={t('Cancel the download')}
204204
variant="secondary"
205205
fullWidth
206+
autoFocus
206207
onClick={() => onClose()}
207208
>
208209
{t('Cancel')}

src/frontend/apps/impress/src/features/docs/doc-header/components/AlertNetwork.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ export const AlertNetworkModal = ({ onClose }: AlertNetworkModalProps) => {
7575
onClose={() => onClose()}
7676
rightActions={
7777
<>
78-
<Button aria-label={t('OK')} onClick={onClose} color="error">
78+
<Button
79+
aria-label={t('OK')}
80+
onClick={onClose}
81+
color="error"
82+
autoFocus
83+
>
7984
{t('I understand')}
8085
</Button>
8186
</>

src/frontend/apps/impress/src/features/docs/doc-management/components/ModalRemoveDoc.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const ModalRemoveDoc = ({
3838
const { push } = useRouter();
3939
const { hasChildren } = useDocUtils(doc);
4040
const cancelButtonRef = useRef<ButtonElement>(null);
41+
4142
const {
4243
mutate: removeDoc,
4344
isError,
@@ -60,17 +61,14 @@ export const ModalRemoveDoc = ({
6061
},
6162
},
6263
});
63-
64+
// react-aria Popover restores focus to its trigger asynchronously
65+
// when closing, which races with autoFocus when the modal is opened
66+
// from a dropdown. This ensures focus wins after that restoration.
6467
useEffect(() => {
65-
const TIMEOUT_MODAL_MOUNTING = 100;
66-
const timeoutId = setTimeout(() => {
67-
const buttonElement = cancelButtonRef.current;
68-
if (buttonElement) {
69-
buttonElement.focus();
70-
}
71-
}, TIMEOUT_MODAL_MOUNTING);
72-
73-
return () => clearTimeout(timeoutId);
68+
const id = requestAnimationFrame(() => {
69+
cancelButtonRef.current?.focus();
70+
});
71+
return () => cancelAnimationFrame(id);
7472
}, []);
7573

7674
const keyboardAction = useKeyboardAction();
@@ -100,6 +98,7 @@ export const ModalRemoveDoc = ({
10098
aria-label={t('Cancel the deletion')}
10199
variant="secondary"
102100
fullWidth
101+
autoFocus
103102
onClick={handleClose}
104103
onKeyDown={handleCloseKeyDown}
105104
>

src/frontend/apps/impress/src/features/docs/doc-versioning/components/ModalConfirmationVersion.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export const ModalConfirmationVersion = ({
7676
aria-label={`${t('Cancel')} - ${t('Warning')}`}
7777
variant="secondary"
7878
fullWidth
79+
autoFocus
7980
onClick={() => onClose()}
8081
>
8182
{t('Cancel')}

src/frontend/apps/impress/src/features/docs/doc-versioning/components/ModalSelectVersion.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const ModalSelectVersion = ({
132132
</Text>
133133
<ButtonCloseModal
134134
aria-label={t('Close the version history modal')}
135+
autoFocus
135136
onClick={onClose}
136137
size="nano"
137138
/>

0 commit comments

Comments
 (0)