Repository navigation
fix(a11y): Accessibility improvements for WCAG 2.1 Level A compliance #37211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
dfcf5ea
8a1e747
9ae31b6
b53eeab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,91 @@ | ||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * Licensed to the Apache Software Foundation (ASF) under one | ||||||||||||||||||||||||||||||||||||||||||
| * or more contributor license agreements. See the NOTICE file | ||||||||||||||||||||||||||||||||||||||||||
| * distributed with this work for additional information | ||||||||||||||||||||||||||||||||||||||||||
| * regarding copyright ownership. The ASF licenses this file | ||||||||||||||||||||||||||||||||||||||||||
| * to you under the Apache License, Version 2.0 (the | ||||||||||||||||||||||||||||||||||||||||||
| * "License"); you may not use this file except in compliance | ||||||||||||||||||||||||||||||||||||||||||
| * with the License. You may obtain a copy of the License at | ||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||
| * Unless required by applicable law or agreed to in writing, | ||||||||||||||||||||||||||||||||||||||||||
| * software distributed under the License is distributed on an | ||||||||||||||||||||||||||||||||||||||||||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||||||||||||||||||||||||||||||||||||||||||
| * KIND, either express or implied. See the License for the | ||||||||||||||||||||||||||||||||||||||||||
| * specific language governing permissions and limitations | ||||||||||||||||||||||||||||||||||||||||||
| * under the License. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||||||||||
| import { styled } from '@superset-ui/core'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| * SkipLink - WCAG 2.4.1 Bypass Blocks | ||||||||||||||||||||||||||||||||||||||||||
| * Allows keyboard users to skip navigation and jump directly to main content. | ||||||||||||||||||||||||||||||||||||||||||
| * The link is visually hidden but becomes visible when focused. | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const StyledSkipLink = styled.a` | ||||||||||||||||||||||||||||||||||||||||||
| position: absolute; | ||||||||||||||||||||||||||||||||||||||||||
| top: -100px; | ||||||||||||||||||||||||||||||||||||||||||
| left: 0; | ||||||||||||||||||||||||||||||||||||||||||
| background: ${({ theme }) => theme.colors.primary.dark1}; | ||||||||||||||||||||||||||||||||||||||||||
| color: ${({ theme }) => theme.colors.grayscale.light5}; | ||||||||||||||||||||||||||||||||||||||||||
| padding: ${({ theme }) => theme.gridUnit * 3}px ${({ theme }) => theme.gridUnit * 4}px; | ||||||||||||||||||||||||||||||||||||||||||
| z-index: 10000; | ||||||||||||||||||||||||||||||||||||||||||
| text-decoration: none; | ||||||||||||||||||||||||||||||||||||||||||
| font-weight: ${({ theme }) => theme.typography.weights.bold}; | ||||||||||||||||||||||||||||||||||||||||||
| font-size: ${({ theme }) => theme.typography.sizes.m}px; | ||||||||||||||||||||||||||||||||||||||||||
| border-radius: 0 0 ${({ theme }) => theme.borderRadius}px ${({ theme }) => theme.borderRadius}px; | ||||||||||||||||||||||||||||||||||||||||||
| transition: top 0.2s ease-in-out; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| &:focus, | ||||||||||||||||||||||||||||||||||||||||||
| &:focus-visible { | ||||||||||||||||||||||||||||||||||||||||||
| top: 0 !important; | ||||||||||||||||||||||||||||||||||||||||||
| outline: 3px solid ${({ theme }) => theme.colors.primary.light1}; | ||||||||||||||||||||||||||||||||||||||||||
| outline-offset: 2px; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| &:hover { | ||||||||||||||||||||||||||||||||||||||||||
| background: ${({ theme }) => theme.colors.primary.base}; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| `; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| interface SkipLinkProps { | ||||||||||||||||||||||||||||||||||||||||||
| targetId?: string; | ||||||||||||||||||||||||||||||||||||||||||
| children?: React.ReactNode; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const SkipLink: React.FC<SkipLinkProps> = ({ | ||||||||||||||||||||||||||||||||||||||||||
| targetId = 'main-content', | ||||||||||||||||||||||||||||||||||||||||||
| children = 'Skip to main content', | ||||||||||||||||||||||||||||||||||||||||||
| }) => { | ||||||||||||||||||||||||||||||||||||||||||
| const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => { | ||||||||||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||||||||||
| const el = document.getElementById(targetId); | ||||||||||||||||||||||||||||||||||||||||||
| if (el) { | ||||||||||||||||||||||||||||||||||||||||||
| // Make sure the element is focusable and focus it | ||||||||||||||||||||||||||||||||||||||||||
| // Note: We intentionally keep the tabindex to ensure the element remains focusable | ||||||||||||||||||||||||||||||||||||||||||
| // for subsequent keyboard navigation (fixes skip link accessibility) | ||||||||||||||||||||||||||||||||||||||||||
| if (!el.hasAttribute('tabindex')) { | ||||||||||||||||||||||||||||||||||||||||||
| el.setAttribute('tabindex', '-1'); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| el.focus(); | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+68
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Logic bug: the code sets a permanent Severity Level: Critical 🚨- ❌ Skip link keyboard navigation fails reaching main content.
- ⚠️ Keyboard users cannot access targeted content via Tab.
- ⚠️ Breaks WCAG 2.4.1 bypass block compliance.
Suggested change
Steps of Reproduction ✅1. Ensure the SkipLink component is present on a page (component defined at
superset-frontend/src/components/Accessibility/SkipLink.tsx). The click handler starts at
the code around lines 64-76; the relevant block is lines 67-73.
2. Add a target element without an existing tabindex, e.g. <main
id="main-content">...</main>, and confirm no tabindex attribute is present.
3. Focus the SkipLink (Tab until it appears) and activate it (Enter or click). This calls
handleClick() in SkipLink (see lines 64-76), which executes the existing lines 67-73.
4. After activation, the code sets tabindex="-1" on the target and leaves it. Observe that
subsequent Tab presses do NOT reach the main content because tabindex="-1" removes it from
tab order — reproducing the accessibility regression.Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** superset-frontend/src/components/Accessibility/SkipLink.tsx
**Line:** 68:73
**Comment:**
*Logic Error: Logic bug: the code sets a permanent `tabindex="-1"` (when absent) and leaves it on the target element — `tabindex="-1"` removes the element from the keyboard tab order, preventing users from reaching main content via Tab; instead temporarily add `tabindex="-1"` only to programmatically focus and then remove it (after focus) so normal keyboard navigation is preserved.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. |
||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||
| // Fallback to fragment navigation if target not present | ||||||||||||||||||||||||||||||||||||||||||
| window.location.hash = `#${targetId}`; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||||||||||
| <StyledSkipLink | ||||||||||||||||||||||||||||||||||||||||||
| href={`#${targetId}`} | ||||||||||||||||||||||||||||||||||||||||||
| className="a11y-skip-link" | ||||||||||||||||||||||||||||||||||||||||||
| onClick={handleClick} | ||||||||||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||||||||||
| {children} | ||||||||||||||||||||||||||||||||||||||||||
| </StyledSkipLink> | ||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export default SkipLink; | ||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import React, { createContext, useContext, useState, useCallback, useMemo } from 'react'; | ||
| import { styled } from '@superset-ui/core'; | ||
|
|
||
| /** | ||
| * StatusAnnouncer - WCAG 4.1.3 Status Messages | ||
| * Provides ARIA live regions for screen reader announcements. | ||
| * - Polite region: for non-urgent status updates (loading, saving) | ||
| * - Assertive region: for urgent messages (errors, alerts) | ||
| */ | ||
|
|
||
| const VisuallyHidden = styled.div` | ||
| position: absolute; | ||
| width: 1px; | ||
| height: 1px; | ||
| padding: 0; | ||
| margin: -1px; | ||
| overflow: hidden; | ||
| clip: rect(0, 0, 0, 0); | ||
| white-space: nowrap; | ||
| border: 0; | ||
| `; | ||
|
|
||
| interface AnnouncerContextType { | ||
| announcePolite: (message: string) => void; | ||
| announceAssertive: (message: string) => void; | ||
| } | ||
|
|
||
| const AnnouncerContext = createContext<AnnouncerContextType | null>(null); | ||
|
|
||
| export const useAnnouncer = (): AnnouncerContextType => { | ||
| const context = useContext(AnnouncerContext); | ||
| if (!context) { | ||
| // Return no-op functions if used outside provider | ||
| return { | ||
| announcePolite: () => {}, | ||
| announceAssertive: () => {}, | ||
| }; | ||
| } | ||
| return context; | ||
| }; | ||
|
|
||
| interface StatusAnnouncerProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export const StatusAnnouncerProvider: React.FC<StatusAnnouncerProps> = ({ children }) => { | ||
| const [politeMessage, setPoliteMessage] = useState(''); | ||
| const [assertiveMessage, setAssertiveMessage] = useState(''); | ||
|
|
||
| const announcePolite = useCallback((message: string) => { | ||
| // Clear first to ensure re-announcement of same message | ||
| setPoliteMessage(''); | ||
| setTimeout(() => setPoliteMessage(message), 100); | ||
| }, []); | ||
|
|
||
| const announceAssertive = useCallback((message: string) => { | ||
| setAssertiveMessage(''); | ||
| setTimeout(() => setAssertiveMessage(message), 100); | ||
| }, []); | ||
|
|
||
| const contextValue = useMemo( | ||
| () => ({ announcePolite, announceAssertive }), | ||
| [announcePolite, announceAssertive] | ||
| ); | ||
|
|
||
| return ( | ||
| <AnnouncerContext.Provider value={contextValue}> | ||
| {children} | ||
| {/* Polite live region for status updates */} | ||
| <VisuallyHidden | ||
| id="a11y-status-announcer" | ||
| role="status" | ||
| aria-live="polite" | ||
| aria-atomic="true" | ||
| > | ||
| {politeMessage} | ||
| </VisuallyHidden> | ||
| {/* Assertive live region for alerts/errors */} | ||
| <VisuallyHidden | ||
| id="a11y-alert-announcer" | ||
| role="alert" | ||
| aria-live="assertive" | ||
| aria-atomic="true" | ||
| > | ||
| {assertiveMessage} | ||
| </VisuallyHidden> | ||
| </AnnouncerContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export default StatusAnnouncerProvider; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| /** | ||
| * Accessibility Components for WCAG 2.1 Level A Compliance | ||
| * | ||
| * This module provides accessibility utilities for Apache Superset: | ||
| * - SkipLink: WCAG 2.4.1 - Bypass Blocks | ||
| * - StatusAnnouncer: WCAG 4.1.3 - Status Messages | ||
| */ | ||
|
|
||
| export { default as SkipLink } from './SkipLink'; | ||
| export { StatusAnnouncerProvider, useAnnouncer } from './StatusAnnouncer'; |
Uh oh!
There was an error while loading. Please reload this page.