Add focus restoration to ManageCookies button (CORE-1503)#110
Draft
OpenStaxClaude wants to merge 1 commit intomainfrom
Draft
Add focus restoration to ManageCookies button (CORE-1503)#110OpenStaxClaude wants to merge 1 commit intomainfrom
OpenStaxClaude wants to merge 1 commit intomainfrom
Conversation
Implements WCAG-compliant focus restoration for the Manage Cookies button when the CookieYes modal closes. Changes: - Added MutationObserver to detect when CookieYes modal closes - Store button reference when clicked - Restore focus to button when cky-modal-open class is removed - Cleanup observer on component unmount to prevent memory leaks Implementation: - Uses MutationObserver to watch for class changes on .cky-modal element - Detects when cky-modal-open class is removed (modal closed) - Small 100ms delay allows CookieYes to add modal to DOM - Properly cleans up observer when done or on unmount This ensures keyboard users don't lose their place when closing the CookieYes modal, addressing critical accessibility violations identified in CORE-1503. Jira: https://openstax.atlassian.net/browse/CORE-1503 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
d56652e to
a33d3ed
Compare
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
Implements WCAG-compliant focus restoration for the Manage Cookies button when the CookieYes modal closes, addressing a critical accessibility violation.
Jira Ticket: https://openstax.atlassian.net/browse/CORE-1503
Problem
When users close the CookieYes cookie consent modal, keyboard focus does not return to the "Manage Cookies" button that opened it. This violates WCAG 2.4.3 (Focus Order) and causes:
Solution
Added focus restoration logic to the
ManageCookiesLinkcomponent that:cky-modal-openclass being removed from the.cky-modalelementbutton.focus()when modal closesImplementation Details
Key Approach
Based on Roy Johnson's investigation, CookieYes maintains a
.cky-modaldiv in the DOM that:cky-modal-openclass when the modal is opencky-modal-openclass removed when the modal closesThis predictable class change allows us to use a MutationObserver to detect modal closure without relying on CookieYes events (which don't exist for modal close actions).
Code Changes
buttonRefto capture the button elementobserverRefto track the MutationObserver instancehandleClickhandler that:.cky-modalfor class changescky-modal-openis removedTesting
Manual Testing Steps
Expected Behavior
Browser Compatibility
Uses standard browser APIs:
MutationObserver- Supported in all modern browsersclassList.contains()- Widely supportedElement.focus()- Universal supportImpact
This change affects all uses of
ManageCookiesLinkacross OpenStax products, including:Since the change is self-contained in the component, no updates to consuming code are required.
WCAG Compliance
This implementation follows WCAG 2.1 Level AA guidelines:
References:
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 noreply@anthropic.com