Skip to content

fix(accessibility): ensure screen reader announcements update consistently#1973

Open
cyphercodes wants to merge 2 commits intoclauderic:masterfrom
cyphercodes:fix-announcement-updates
Open

fix(accessibility): ensure screen reader announcements update consistently#1973
cyphercodes wants to merge 2 commits intoclauderic:masterfrom
cyphercodes:fix-announcement-updates

Conversation

@cyphercodes
Copy link
Copy Markdown

Fixes #1952 - The useAnnouncement hook now clears the announcement before setting the new value, using requestAnimationFrame to ensure screen readers detect the change.

…ently

The useAnnouncement hook was not reliably updating screen reader
announcements when dragging sortable items. This was because React
batches state updates, causing consecutive identical announcements
to be skipped by assistive technologies.

The fix clears the announcement before setting the new value,
using requestAnimationFrame to ensure the DOM update is flushed
between the clear and the new announcement. This creates a detectable
change that screen readers will announce.

Fixes clauderic#1952
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 28, 2026

🦋 Changeset detected

Latest commit: 614e8c2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@dnd-kit/accessibility Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@clauderic clauderic added bug Something isn't working a11y labels Mar 29, 2026
Copy link
Copy Markdown
Owner

@clauderic clauderic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR fixes an issue where screen readers don't re-announce identical text content. It uses a clear-then-set pattern via requestAnimationFrame to force the screen reader to detect the change.

Feedback

Blocking issues

  • Missing changeset: packages/accessibility/src/hooks/useAnnouncement.ts is a source file in a published package, so a changeset entry is required. Please add a .changeset/*.md file listing @dnd-kit/accessibility with a patch bump.

  • Base branch: This PR targets master (the legacy branch), not main (the active development branch). Please double-check which branch you intended to target. If this is intentional for the legacy package, that's fine — just worth confirming.

Suggestions

  • packages/accessibility/src/hooks/useAnnouncement.ts — The requestAnimationFrame callback isn't cancelled if the component unmounts before the frame fires. While React 18 makes this a no-op (no warning), a cleaner pattern would be to return a cancel handle. For example:

    const announce = useCallback((value: string | undefined) => {
      if (value != null) {
        setAnnouncement('');
        const rafId = requestAnimationFrame(() => {
          setAnnouncement(value);
        });
        return () => cancelAnimationFrame(rafId);
      }
    }, []);

    This is a suggestion, not a blocker — the current approach will work correctly in React 18+.

Changeset

  • Status: missing. A changeset is required for changes to packages/*/src/.

Overall

Great fix for a subtle screen reader issue — the clear-then-rAF pattern is the right approach here. Thanks for contributing! Once the changeset is added, this looks good to go.


[claude-review]

@cyphercodes
Copy link
Copy Markdown
Author

Thanks for the review. I pushed 614e8c2b with the required changeset:

  • Added .changeset/stale-owls-search.md with a patch bump for @dnd-kit/accessibility.
  • Verified it with npx --yes @changesets/cli@2.16.0 status --since=HEAD~1; it reports @dnd-kit/accessibility as a patch bump.

I left the PR targeting master: this branch's changeset config uses baseBranch: "master", and the touched legacy package path (packages/accessibility/src/hooks/useAnnouncement.ts) does not exist on main's current package layout. If you prefer a separate main-branch implementation, I can handle that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a11y bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants