Skip to content

Commit

Permalink
Use aria-live="polite" for announcements (#1229)
Browse files Browse the repository at this point in the history
* Use `aria-live="polite"` for announcements

* Update `ariaLiveType` default value to `assertive`

* Add changeset

---------

Co-authored-by: Claudéric Demers <clauderic.d@gmail.com>
  • Loading branch information
ayy-bc and clauderic committed Nov 6, 2023
1 parent bc588c7 commit aabb8bd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/configure-aria-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@dnd-kit/accessibility": minor
---

Introduce `ariaLiveType` prop on `<LiveRegion>` to allow consumers to configure the `aria-live` attribute to other values for announcements, such as `aria-live="polite"`.
33 changes: 17 additions & 16 deletions packages/accessibility/src/components/LiveRegion/LiveRegion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,30 @@ import React from 'react';
export interface Props {
id: string;
announcement: string;
ariaLiveType?: "polite" | "assertive" | "off";
}

// Hide element visually but keep it readable by screen readers
const visuallyHidden: React.CSSProperties = {
position: 'fixed',
width: 1,
height: 1,
margin: -1,
border: 0,
padding: 0,
overflow: 'hidden',
clip: 'rect(0 0 0 0)',
clipPath: 'inset(100%)',
whiteSpace: 'nowrap',
};

export function LiveRegion({id, announcement}: Props) {
export function LiveRegion({id, announcement, ariaLiveType = "assertive"}: Props) {
// Hide element visually but keep it readable by screen readers
const visuallyHidden: React.CSSProperties = {
position: 'fixed',
width: 1,
height: 1,
margin: -1,
border: 0,
padding: 0,
overflow: 'hidden',
clip: 'rect(0 0 0 0)',
clipPath: 'inset(100%)',
whiteSpace: 'nowrap',
};
return (
<div
id={id}
style={visuallyHidden}
role="status"
aria-live="assertive"
aria-live={ariaLiveType}
aria-atomic
>
{announcement}
Expand Down

0 comments on commit aabb8bd

Please sign in to comment.