Skip to content

Commit

Permalink
get screen readers to announce form success and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
echappen committed Sep 13, 2024
1 parent 95be14d commit 0bdf344
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/UsersActions/UsersActionsOrgRoles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export function UsersActionsOrgRoles({

return (
<>
{/* aria-live region needs to show up on initial page render. */}
<div
role="region"
aria-live="polite"
aria-atomic={true}
className="usa-sr-only"
>
{actionErrors.join(', ')}
</div>
{actionStatus === 'success' && (
<Alert type="success">Org roles have been saved!</Alert>
)}
Expand Down
12 changes: 11 additions & 1 deletion src/components/UsersList/UsersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ export function UsersList({
const usernameText = username ? `for ${username}` : '';
const rolesText = type === 'org' ? 'organization' : 'space';
const msg = `The ${rolesText} roles ${usernameText} have been updated.`;
setSuccessMsg(msg);
closeOverlay();
// delaying this to get aria-live region to announce success
setTimeout(() => {
setSuccessMsg(msg);
}, 500);
};

// Success alert
Expand All @@ -159,6 +162,13 @@ export function UsersList({

return (
<>
{/*
aria-live region needs to show up on initial page render.
More info: https://tetralogical.com/blog/2024/05/01/why-are-my-live-regions-not-working/
*/}
<div role="region" aria-live="assertive" aria-atomic={true}>
{successMsg}
</div>
<OverlayDrawer
ariaLabel={overlayAriaLabel}
id="overlay-drawer-manage-users"
Expand Down

0 comments on commit 0bdf344

Please sign in to comment.