Skip to content

♿ [Story a11y] Restore focus when system-layer paired buttons toggle visibility#40504

Draft
michaeldegori wants to merge 1 commit into
ampproject:mainfrom
michaeldegori:fix/story-system-layer-button-focus
Draft

♿ [Story a11y] Restore focus when system-layer paired buttons toggle visibility#40504
michaeldegori wants to merge 1 commit into
ampproject:mainfrom
michaeldegori:fix/story-system-layer-button-focus

Conversation

@michaeldegori
Copy link
Copy Markdown

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 is display: block !important based 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 tryFocus from #core/dom. Programmatic state changes (autoplay, viewer messaging) do not steal focus.

Touches onCaptionsStateUpdate_, onMutedStateUpdate_, and onPausedStateUpdate_ in extensions/amp-story/1.0/amp-story-system-layer.js. Adds 9 unit tests in test-amp-story-system-layer.js covering 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant