Skip to content

Internalize role="timer" codepen demo #39729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025

Conversation

Josh-Cena
Copy link
Member

This example is straightforward. I copied it over, modernized the code, and added some explanations.

@Josh-Cena Josh-Cena requested a review from a team as a code owner May 29, 2025 06:57
@Josh-Cena Josh-Cena requested review from scottaohara and removed request for a team May 29, 2025 06:57
@github-actions github-actions bot added Content:Accessibility Accessibility docs size/m [PR only] 51-500 LoC changed labels May 29, 2025
Copy link
Contributor

@Josh-Cena Josh-Cena requested a review from bsmth June 3, 2025 12:47
Copy link
Member

@bsmth bsmth left a comment

Choose a reason for hiding this comment

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

Thanks!

@Josh-Cena Josh-Cena merged commit a05c5f0 into mdn:main Jun 4, 2025
7 checks passed
@Josh-Cena Josh-Cena deleted the internalize-timer-example branch June 4, 2025 11:49

### A basic timer

This example has a timer that counts down from 30 seconds to 0 seconds. The whole time display region has `role="time"`, and also [`aria-atomic`](/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-atomic) to indicate that the region should be announced as a whole, not just the changed regions. Due to the implicit `aria-live="off"`, changes are not announced by default; we manually set it to `"assertive"` when the timer reaches 10 seconds remaining so it gets announced once.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This example has a timer that counts down from 30 seconds to 0 seconds. The whole time display region has `role="time"`, and also [`aria-atomic`](/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-atomic) to indicate that the region should be announced as a whole, not just the changed regions. Due to the implicit `aria-live="off"`, changes are not announced by default; we manually set it to `"assertive"` when the timer reaches 10 seconds remaining so it gets announced once.
This example has a timer that counts down from 30 seconds to 0 seconds. The whole time display region has `role="timer"`, and also [`aria-atomic`](/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-atomic) to indicate that the region should be announced as a whole, not just the changed regions. Due to the implicit `aria-live="off"`, changes are not announced by default; we manually set it to `"assertive"` when the timer reaches 10 seconds remaining so it gets announced once.

}

if (newNumber === 10) {
liveRegion.setAttribute("aria-live", "assertive");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why aria live assertive and role=alert which is already a slightly more powerful aria-live assertive implicitly ?

@scottaohara
Copy link
Contributor

@Josh-Cena of course this gets merged as I find a typo and have a question in my review…

@Josh-Cena
Copy link
Member Author

Oh oops. Would send a follow up.

Why aria live assertive and role=alert which is already a slightly more powerful aria-live assertive implicitly ?

I'm not sure; this is already in the example I copied over. Which would you reckon as redundant? Happy to make modifications.

@scottaohara
Copy link
Contributor

Aria-live isn’t needed if the element is also being changed to a role=alert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:Accessibility Accessibility docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants