Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions superset-frontend/src/components/Accessibility/SkipLink.tsx
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();
Comment on lines +68 to +73

Copy link
Copy Markdown
Contributor

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 add tabindex="-1" only to programmatically focus and then remove it (after focus) so normal keyboard navigation is preserved. [logic error]

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
// 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();
// Temporarily add tabindex so we can programmatically focus, then remove it to preserve tab order
const _addedTabIndex = !el.hasAttribute('tabindex');
if (_addedTabIndex) {
el.setAttribute('tabindex', '-1');
}
el.focus();
if (_addedTabIndex) {
// Remove the temporary tabindex on the next macrotask to ensure focus is retained
window.setTimeout(() => {
if (document.body.contains(el)) {
el.removeAttribute('tabindex');
}
}, 0);
}
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.

if (!hadTabIndex) {
el.removeAttribute('tabindex');
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 suggestion
Check the AI-generated fix before applying
Suggested change
el.focus();
if (!hadTabIndex) {
el.removeAttribute('tabindex');
}
el.focus();

Code Review Run #bd4964


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

} 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;
109 changes: 109 additions & 0 deletions superset-frontend/src/components/Accessibility/StatusAnnouncer.tsx
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;
29 changes: 29 additions & 0 deletions superset-frontend/src/components/Accessibility/index.tsx
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';
Loading