Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Commit

Permalink
[AUD-1362] Fix modal a11y (#85)
Browse files Browse the repository at this point in the history
- Adds dialog role
- Adds aria-labelledby and aria-describedby for title and subtitle
  • Loading branch information
dylanjeffers committed Jan 25, 2022
1 parent 3a4ace9 commit 487a0f2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/stems/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(
ref
) {
const id = useMemo(() => modalKey || uniqueId('modal-'), [modalKey])
const titleId = `${id}-title`
const subtitleId = `${id}-subtitle`
const onTouchMove = useCallback(
(e: any) => {
!allowScroll && e.preventDefault()
Expand Down Expand Up @@ -249,7 +251,9 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(
ref={dismissOnClickOutside ? outsideClickRef : null}
className={bodyClassNames}
style={{ ...props, ...bodyOffset, ...bodyStyle }}
key={key}
role='dialog'
aria-labelledby={titleId}
aria-describedby={subtitleId}
>
<>
{showTitleHeader && (
Expand All @@ -262,10 +266,14 @@ export const Modal = forwardRef<HTMLDivElement, ModalProps>(function Modal(
<IconRemove />
</div>
)}
<div className={cn(styles.header, titleClassName)}>
<div
id={titleId}
className={cn(styles.header, titleClassName)}
>
{title}
</div>
<div
id={subtitleId}
className={cn(styles.subtitle, subtitleClassName)}
>
{subtitle}
Expand Down

0 comments on commit 487a0f2

Please sign in to comment.