Skip to content

Commit eb5a8cb

Browse files
authored
Dialog, Drawer: Prevent close button from being aria-hidden (#1792)
1 parent 5ea5167 commit eb5a8cb

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.changeset/twelve-emus-clap.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'braid-design-system': patch
3+
---
4+
5+
---
6+
updated:
7+
- Dialog
8+
- Drawer
9+
---
10+
11+
**Dialog, Drawer**: Ensure that only elements outside the `Dialog` or `Drawer` are `aria-hidden` when open
12+
13+
Fixes an issue where the close button inside the `Dialog` or `Drawer` was incorrectly inside an `aria-hidden` region.

packages/braid-design-system/src/lib/components/private/Modal/ModalContent.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export const ModalContent = ({
102102
...restProps
103103
}: ModalContentProps) => {
104104
const resolvedId = useFallbackId(id);
105-
106105
const descriptionId = useId();
107106

108107
const defaultModalRef = useRef<HTMLElement>(null);
@@ -140,6 +139,7 @@ export const ModalContent = ({
140139
justifyContent={justifyContent}
141140
>
142141
<Box
142+
ref={modalRef}
143143
position="relative"
144144
display="flex"
145145
alignItems="center"
@@ -153,10 +153,8 @@ export const ModalContent = ({
153153
width={width !== 'content' ? 'full' : undefined}
154154
maxWidth={width !== 'content' ? width : undefined}
155155
>
156-
{/* modalRef gets forwarded down to child element by RemoveScroll by `forwardProps` */}
157156
<RemoveScroll
158157
noRelative // Allows portalled elements to be positioned correctly relative to the viewport size
159-
ref={modalRef}
160158
forwardProps
161159
enabled={scrollLock}
162160
>

packages/braid-design-system/src/lib/components/private/Modal/modalTestSuite.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,24 @@ export const modalTestSuite = (
228228
}
229229
expect(queryByRole('dialog')).not.toBeInTheDocument();
230230
});
231+
232+
it('should have a close button that is not aria-hidden', async () => {
233+
const { getByTestId, queryByRole } = renderTestCase();
234+
235+
const dialogOpenButton = getByTestId('buttonBefore');
236+
await userEvent.click(dialogOpenButton);
237+
238+
// Waiting for `ariaHideOthers` to apply
239+
await waitFor(() =>
240+
expect(document.querySelector('[data-aria-hidden]')).not.toBeNull(),
241+
);
242+
243+
const closeButton = queryByRole('button', {
244+
name: CLOSE_LABEL,
245+
hidden: false,
246+
});
247+
248+
expect(closeButton).not.toBeNull();
249+
});
231250
});
232251
};

0 commit comments

Comments
 (0)