Skip to content

Commit

Permalink
feat: Add closeButtonAriaLabel to Modal Component (#959)
Browse files Browse the repository at this point in the history
Co-authored-by: Alan B Smith <alanbsmith@users.noreply.github.com>
  • Loading branch information
UltraTempest and alanbsmith committed Feb 4, 2021
1 parent 339be74 commit 221fa1c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
6 changes: 6 additions & 0 deletions modules/modal/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ default behavior.

If this ref is not provided the modal will try to use the close icon. If that icon is not available,
it will make the modal heading focusable and focus on that instead.

#### `closeButtonAriaLabel: string`

> Aria label string for the close icon button
---
6 changes: 6 additions & 0 deletions modules/modal/react/lib/ModalContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export interface ModalContentProps extends React.HTMLAttributes<HTMLDivElement>
* @default document.body
*/
container?: HTMLElement;
/**
* The `aria-label` for the Popup close button.
*/
closeButtonAriaLabel?: string;
}

const fadeIn = keyframes`
Expand Down Expand Up @@ -193,6 +197,7 @@ const ModalContent = ({
children,
firstFocusRef,
heading,
closeButtonAriaLabel,
...elemProps
}: ModalContentProps) => {
const centeringRef = React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -228,6 +233,7 @@ const ModalContent = ({
transformOrigin={transformOrigin}
aria-modal={true}
ariaLabel={ariaLabel}
closeButtonAriaLabel={closeButtonAriaLabel}
>
{children}
</Popup>
Expand Down
8 changes: 4 additions & 4 deletions modules/modal/react/spec/Modal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ describe('Modal', () => {
);
});

test('Modal should replace aria-labeldBy with custom aria-label', () => {
const customAriaLabel = 'custom aria label';
const {getByRole} = renderModal({ariaLabel: customAriaLabel});
expect(getByRole('dialog')).toHaveAttribute('aria-label', customAriaLabel);
test('Modal should forward closeButtonAriaLabel prop to Popup', () => {
const closeButtonAriaLabel = 'close button aria label';
const {getByRole} = renderModal({closeButtonAriaLabel});
expect(getByRole('button')).toHaveAttribute('aria-label', closeButtonAriaLabel);
});
});
2 changes: 1 addition & 1 deletion modules/popup/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ Default: `PopupPadding.l`
---
#### `closeLabel: string`
#### `closeButtonAriaLabel: string`
> Aria label string for the close icon button
Expand Down

0 comments on commit 221fa1c

Please sign in to comment.