Skip to content

Commit

Permalink
[misc enhancement] Allow consumers to pass custom aria-describedby
Browse files Browse the repository at this point in the history
…IDs to flyouts
  • Loading branch information
cee-chen committed Aug 10, 2023
1 parent d84f0c6 commit 0d7df8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/components/flyout/flyout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ describe('EuiFlyout', () => {
).toBeFalsy();
});

it('allows setting custom aria-describedby attributes', () => {
const { getByTestSubject } = render(
<>
<EuiFlyout
onClose={() => {}}
aria-describedby="custom-test-id"
data-test-subj="flyout"
/>
<div id="custom-test-id" hidden>
This flyout does X, Y, and Z
</div>
</>
);
expect(getByTestSubject('flyout')).toHaveAttribute(
'aria-describedby',
'generated-id custom-test-id'
);
});

describe('props', () => {
test('hideCloseButton', () => {
const component = mount(<EuiFlyout onClose={() => {}} hideCloseButton />);
Expand Down
4 changes: 3 additions & 1 deletion src/components/flyout/flyout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const EuiFlyout = forwardRef(
pushMinBreakpoint = 'l',
focusTrapProps: _focusTrapProps = {},
includeFixedHeadersInFocusTrap = true,
'aria-describedby': _ariaDescribedBy,
...rest
}: EuiFlyoutProps<T>,
ref:
Expand Down Expand Up @@ -349,6 +350,7 @@ export const EuiFlyout = forwardRef(
*/
const hasOverlayMask = ownFocus && !isPushed;
const descriptionId = useGeneratedHtmlId();
const ariaDescribedBy = classnames(descriptionId, _ariaDescribedBy);

const screenReaderDescription = (
<EuiScreenReaderOnly>
Expand Down Expand Up @@ -416,7 +418,7 @@ export const EuiFlyout = forwardRef(
{...(rest as ComponentPropsWithRef<T>)}
role={!isPushed ? 'dialog' : rest.role}
tabIndex={!isPushed ? 0 : rest.tabIndex}
aria-describedby={!isPushed ? descriptionId : undefined}
aria-describedby={!isPushed ? ariaDescribedBy : _ariaDescribedBy}
data-autofocus={!isPushed || undefined}
>
{!isPushed && screenReaderDescription}
Expand Down

0 comments on commit 0d7df8a

Please sign in to comment.