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 1 commit
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,93 @@ | ||||||||||||
| /** | ||||||||||||
| * 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, focus it, then clean up any temporary tabindex | ||||||||||||
| const hadTabIndex = el.hasAttribute('tabindex'); | ||||||||||||
| if (!hadTabIndex) { | ||||||||||||
| el.setAttribute('tabindex', '-1'); | ||||||||||||
| } | ||||||||||||
| el.focus(); | ||||||||||||
| if (!hadTabIndex) { | ||||||||||||
| el.removeAttribute('tabindex'); | ||||||||||||
| } | ||||||||||||
|
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. Skip link breaks target focusability
The handleClick function adds tabindex='-1' to non-focusable elements to enable programmatic focus, but then removes it afterward, making the target unfocusable again. This breaks skip link functionality for elements that weren't originally focusable. The tabindex should be left in place to maintain focusability. Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #bd4964 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||||||||
| } 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'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: 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 addtabindex="-1"only to programmatically focus and then remove it (after focus) so normal keyboard navigation is preserved. [logic error]Severity Level: Critical 🚨
Steps of Reproduction ✅
Prompt for AI Agent 🤖