Skip to content

Commit ce49862

Browse files
author
katiegoines
committed
focus modal on open
1 parent 98efe01 commit ce49862

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/components/ApiDocs/display/ApiModal.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ParameterType } from './ParameterType';
66
import { ApiComment } from '../ApiComment';
77
import { LinkDataType, TypeLinkInterface } from './TypeLink';
88
import references from '@/directory/apiReferences.json';
9+
import { useRef } from 'react';
910

1011
interface ApiModalInterface {
1112
data: any;
@@ -26,6 +27,7 @@ export const ApiModal = ({
2627
data = references[data.target];
2728
}
2829
const description = data?.comment?.summary;
30+
const ref = useRef<HTMLDivElement>(null);
2931

3032
const closeModal = () => {
3133
clearBC();
@@ -84,10 +86,18 @@ export const ApiModal = ({
8486
}, [] as TypeLinkInterface[])
8587
: [];
8688

89+
if (showModal) {
90+
setTimeout(() => {
91+
ref?.current?.focus();
92+
}, 0);
93+
}
94+
8795
return (
8896
<View
8997
aria-label={`${name} API Reference`}
9098
className={`api-modal-container${showModal ? ' api-modal-container--open' : ''}`}
99+
ref={ref}
100+
tabIndex={0}
91101
>
92102
<Card as="dialog" className="api-modal" aria-modal="true">
93103
<Flex className="api-model__header">
@@ -97,6 +107,7 @@ export const ApiModal = ({
97107
size="small"
98108
variation="link"
99109
className="api-modal__close"
110+
aria-label="Close"
100111
>
101112
<IconX />
102113
</Button>

0 commit comments

Comments
 (0)