♿ 🐛 [Story system-layer] Restore focus after paired button toggles#1
Closed
michaeldegori wants to merge 1 commit into
Closed
♿ 🐛 [Story system-layer] Restore focus after paired button toggles#1michaeldegori 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.
Owner
Author
|
Superseded by upstream PR ampproject#40504. |
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.
Summary
Restores keyboard and screen-reader focus after the AMP Story system layer toggles between paired sibling buttons (captions on/off, mute/unmute, pause/play). Without this fix, activating one of those buttons via keyboard loses focus on desktop, and iOS VoiceOver lands on a hidden sibling.
Why
Each pair renders as two sibling
<button>elements; CSS swaps which one isdisplay: block !importantbased on a host attribute. When the user activates the visible button, the attribute flips and the just-clicked button becomesdisplay: none, so the browser blurs it. Assistive tech treats this as confusing focus loss.The fix moves focus to the now-visible sibling, but only when the just-hidden sibling held focus before the state change. Programmatic state changes (autoplay, viewer messaging) do not steal focus.
Changes
extensions/amp-story/1.0/amp-story-system-layer.js:activeElementHasClass_(predicate) andfocusButton_(usestryFocusfrom#core/dom).onCaptionsStateUpdate_,onMutedStateUpdate_, andonPausedStateUpdate_: captures whether the just-hidden sibling holds focus before the attribute mutation, then callsfocusButton_on the now-visible sibling.extensions/amp-story/1.0/test/test-amp-story-system-layer.js:Repro (without this fix)
Tests
npx amp linton the changed files: clean.npx amp unit --files=extensions/amp-story/1.0/test/test-amp-story-system-layer.js: 29 passing, 1 pre-existing skip.