Skip to content

Commit b4a83fc

Browse files
Koljaclaude
andcommitted
fix(a11y): WCAG 2.4.7 — scope focus-visible to interactive elements and document WCAG trade-offs
Addresses Rusackas' review feedback while preserving WCAG conformance. GlobalStyles.tsx: - Replace the global `*:focus-visible` selector with an explicit list of interactive elements (native focusable elements, common ARIA roles, AntD wrappers), wrapped in :where() so the rule stays at specificity (0,0,1,0) and remains overridable by component-level styles. - Keep !important on the outline declarations with an inline rationale: AntD ships per-component focus resets like `.ant-btn:focus { outline: 0 }` at the same specificity, and its runtime-injected styles can land after this global block. Without !important the WCAG 2.4.7 focus indicator silently disappears on AntD components. TimeFilterPlugin.tsx: - Document why this file uses `theme.colorPrimary` instead of the default `theme.controlOutline` token: `controlOutline` is a low-alpha tint of colorPrimary that typically fails WCAG 1.4.11 (3:1 non-text contrast). Reverting to `controlOutline` would regress 1.4.11, so the swap stays but is now explicitly annotated. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ffee2f3 commit b4a83fc

2 files changed

Lines changed: 59 additions & 5 deletions

File tree

‎superset-frontend/packages/superset-core/src/theme/GlobalStyles.tsx‎

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,54 @@ export const GlobalStyles = () => {
116116
margin-top: ${theme.marginXS}px;
117117
}
118118
119-
/* WCAG 2.4.7: Focus Visible — ensure all interactive elements have a visible
120-
keyboard focus indicator. Uses :focus-visible to avoid showing on mouse clicks.
121-
Individual components can override with their own focus styles. */
122-
*:focus-visible {
119+
/* WCAG 2.4.7: Focus Visible — give every interactive element a visible
120+
keyboard focus indicator. Uses :focus-visible so the ring only shows
121+
on keyboard navigation, not on mouse clicks.
122+
123+
Selector scope: limited to actually interactive elements (native
124+
focusable elements plus AntD wrappers and common ARIA roles) instead
125+
of the universal "*", so non-interactive elements that happen to
126+
receive programmatic focus do not pick up an unwanted outline.
127+
Wrapped in :where() so the rule keeps specificity (0,0,1,0) and
128+
remains easy for component-level styles to override.
129+
130+
Why !important: AntD ships per-component focus resets such as
131+
".ant-btn:focus { outline: 0 }" with the same (0,0,2,0) specificity
132+
as a hypothetical un-flagged ".ant-btn:focus-visible" rule here, and
133+
AntD's runtime-injected styles can land after this global block.
134+
!important is the only way to guarantee the WCAG focus indicator is
135+
not silently reset back to outline:0. Components that genuinely need
136+
a different focus treatment must use !important themselves, matching
137+
AntD's own pattern. */
138+
:where(
139+
a,
140+
button,
141+
input,
142+
select,
143+
textarea,
144+
[tabindex],
145+
[role='button'],
146+
[role='link'],
147+
[role='menuitem'],
148+
[role='tab'],
149+
[role='checkbox'],
150+
[role='option'],
151+
[role='combobox'],
152+
[role='switch'],
153+
.ant-btn,
154+
.ant-input,
155+
.ant-input-affix-wrapper,
156+
.ant-input-number,
157+
.ant-select-selector,
158+
.ant-checkbox-input,
159+
.ant-radio-input,
160+
.ant-switch,
161+
.ant-picker,
162+
.ant-cascader-picker,
163+
.ant-dropdown-trigger,
164+
.ant-tabs-tab,
165+
.ant-menu-item
166+
):focus-visible {
123167
outline: 2px solid ${theme.colorPrimary} !important;
124168
outline-offset: 2px !important;
125169
}

‎superset-frontend/src/filters/components/Time/TimeFilterPlugin.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,19 @@ const ControlContainer = styled.div<{
6161
}
6262
6363
&:focus > div {
64+
/* WCAG 1.4.11: Non-text contrast — the focus indicator needs at least 3:1
65+
against the adjacent background. The default "theme.controlOutline"
66+
token is a low-alpha tint derived from colorPrimary and typically lands
67+
below 3:1, so we use full-saturation "theme.colorPrimary" here instead.
68+
Do not revert to "controlOutline" without first confirming the active
69+
theme satisfies 3:1 — otherwise this regresses 1.4.11.
70+
71+
WCAG 2.4.7: The transparent outline keeps a visible focus ring in
72+
Windows High Contrast / forced-colors mode, where box-shadows are
73+
suppressed but outlines are honoured. */
6474
border-color: ${({ theme }) => theme.colorPrimary};
6575
box-shadow: ${({ theme }) => `0 0 0 2px ${theme.colorPrimary}`};
66-
outline: 2px solid transparent; /* WCAG 2.4.7: transparent outline prevents double-ring; box-shadow provides visible focus */
76+
outline: 2px solid transparent;
6777
}
6878
`;
6979

0 commit comments

Comments
 (0)