Skip to content

Commit 0d7df8a

Browse files
committed
[misc enhancement] Allow consumers to pass custom aria-describedby IDs to flyouts
1 parent d84f0c6 commit 0d7df8a

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/components/flyout/flyout.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ describe('EuiFlyout', () => {
7171
).toBeFalsy();
7272
});
7373

74+
it('allows setting custom aria-describedby attributes', () => {
75+
const { getByTestSubject } = render(
76+
<>
77+
<EuiFlyout
78+
onClose={() => {}}
79+
aria-describedby="custom-test-id"
80+
data-test-subj="flyout"
81+
/>
82+
<div id="custom-test-id" hidden>
83+
This flyout does X, Y, and Z
84+
</div>
85+
</>
86+
);
87+
expect(getByTestSubject('flyout')).toHaveAttribute(
88+
'aria-describedby',
89+
'generated-id custom-test-id'
90+
);
91+
});
92+
7493
describe('props', () => {
7594
test('hideCloseButton', () => {
7695
const component = mount(<EuiFlyout onClose={() => {}} hideCloseButton />);

src/components/flyout/flyout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export const EuiFlyout = forwardRef(
183183
pushMinBreakpoint = 'l',
184184
focusTrapProps: _focusTrapProps = {},
185185
includeFixedHeadersInFocusTrap = true,
186+
'aria-describedby': _ariaDescribedBy,
186187
...rest
187188
}: EuiFlyoutProps<T>,
188189
ref:
@@ -349,6 +350,7 @@ export const EuiFlyout = forwardRef(
349350
*/
350351
const hasOverlayMask = ownFocus && !isPushed;
351352
const descriptionId = useGeneratedHtmlId();
353+
const ariaDescribedBy = classnames(descriptionId, _ariaDescribedBy);
352354

353355
const screenReaderDescription = (
354356
<EuiScreenReaderOnly>
@@ -416,7 +418,7 @@ export const EuiFlyout = forwardRef(
416418
{...(rest as ComponentPropsWithRef<T>)}
417419
role={!isPushed ? 'dialog' : rest.role}
418420
tabIndex={!isPushed ? 0 : rest.tabIndex}
419-
aria-describedby={!isPushed ? descriptionId : undefined}
421+
aria-describedby={!isPushed ? ariaDescribedBy : _ariaDescribedBy}
420422
data-autofocus={!isPushed || undefined}
421423
>
422424
{!isPushed && screenReaderDescription}

0 commit comments

Comments
 (0)