fix: Improve live region behavior for short-lived content updates#4310
fix: Improve live region behavior for short-lived content updates#4310avinashbot wants to merge 4 commits intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4310 +/- ##
=======================================
Coverage 97.43% 97.43%
=======================================
Files 896 897 +1
Lines 26298 26347 +49
Branches 9496 9519 +23
=======================================
+ Hits 25623 25672 +49
Misses 632 632
Partials 43 43 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Added a demo page that I was playing around with locally. It seems like the fix causes the "Loading" message to take priority over "Loading complete" (or at least something prevents "Loading complete" from being announced, which I think would be optimal here) |
|
Thanks! Used that as the test-case to fix up the logic. There are still some conflicts because when loading completes, you now have two independent announcements fighting to be announced, so I had to comment out one of them in the test page. I think we'll have to ask for the same changes in the code where this was found. |
| } | ||
| } | ||
|
|
||
| announce({ message, forceReannounce = false }: { message?: string; delay?: number; forceReannounce?: boolean }) { |
There was a problem hiding this comment.
Realized while refactoring that the delay parameter here actually does nothing. I removed it from src/live-region/internal.tsx (and moved it to the class constructor).
Description
One of the common use-cases for the live region component is for announcing content loading/refreshing changes. Something like "Reloading things" -> "Last updated: " (see loading and refreshing). However, the live region deduplicates and throttles updates, which means that this information may not be properly conveyed under certain circumstances.
Loading issues(suppressed if loading takes < 2 seconds)Last updated: December 21, 2023, 14:29(announced)Loading issues(suppressed if loading takes < 2 seconds)Last updated: December 21, 2023, 14:29(suppressed since the text is the same as the last announcement, this is bad)So I updated the controller to force an announcement even if the text is the same if there was an update in between (like the text
Loading issues). Also reduced the delay to 1 second to make the announcements snappier (but I don't feel comfortable going any lower than that in case the live region is used in conjuction with user input)Related links, issue #, if available: AWSUI-61749, AWSUI-61345
How has this been tested?
Updated unit tests.
Review checklist
The following items are to be evaluated by the author(s) and the reviewer(s).
Correctness
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.