♿ [Story a11y] Restore focus when system-layer paired buttons toggle visibility#40504
Draft
michaeldegori wants to merge 1 commit into
Draft
♿ [Story a11y] Restore focus when system-layer paired buttons toggle visibility#40504michaeldegori wants to merge 1 commit into
michaeldegori wants to merge 1 commit into
Conversation
The captions, mute/unmute, and pause/play controls in the story system layer are paired sibling buttons toggled by host attributes that drive display:block via CSS. Clicking one hides it and reveals its sibling, which drops keyboard focus on desktop and lands iOS VoiceOver on a hidden element. Capture whether the just-hidden sibling holds focus before the attribute mutation, then move focus to the now-visible sibling. Programmatic state changes do not move focus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restores keyboard and screen-reader focus after the AMP Story system layer toggles between paired sibling buttons (captions on/off, mute/unmute, pause/play). Each pair is two sibling
<button>elements; CSS swaps which one isdisplay: block !importantbased on a host attribute, so activating the visible button immediately hides it and the browser blurs it. On desktop this loses focus; on iOS VoiceOver focus lands on the hidden sibling.The fix captures whether the just-hidden sibling held focus before the attribute mutation, and only then moves focus to the now-visible sibling via
tryFocusfrom#core/dom. Programmatic state changes (autoplay, viewer messaging) do not steal focus.Touches
onCaptionsStateUpdate_,onMutedStateUpdate_, andonPausedStateUpdate_inextensions/amp-story/1.0/amp-story-system-layer.js. Adds 9 unit tests intest-amp-story-system-layer.jscovering focus restoration and the do-not-steal-focus behavior for each paired toggle.Repro without the fix: tab to the captions, pause, or mute button in any story, activate via Enter or Space, and observe focus is lost on desktop or jumps to a hidden element on iOS VoiceOver.