Skip to content

Commit 1976e36

Browse files
katiekleinkatiegoines
andauthored
focus modal on open (#7970)
Co-authored-by: katiegoines <[email protected]>
1 parent b803bbc commit 1976e36

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/components/ApiDocs/display/ApiModal.tsx

Lines changed: 10 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,6 +86,11 @@ export const ApiModal = ({
8486
}, [] as TypeLinkInterface[])
8587
: [];
8688

89+
if (showModal) {
90+
setTimeout(() => {
91+
ref?.current?.focus();
92+
}, 0);
93+
8794
if (typeof window != 'undefined') {
8895
window.onclick = function (event) {
8996
if (event.target.className.includes('api-modal-container--open')) {
@@ -96,6 +103,8 @@ export const ApiModal = ({
96103
<View
97104
aria-label={`${name} API Reference`}
98105
className={`api-modal-container${showModal ? ' api-modal-container--open' : ''}`}
106+
ref={ref}
107+
tabIndex={0}
99108
>
100109
<Card as="dialog" className="api-modal" aria-modal="true">
101110
<Flex className="api-model__header">
@@ -105,6 +114,7 @@ export const ApiModal = ({
105114
size="small"
106115
variation="link"
107116
className="api-modal__close"
117+
aria-label="Close"
108118
>
109119
<IconX />
110120
</Button>

0 commit comments

Comments
 (0)