From 98b273c3d6978f159befb4454b0c20ab5c895440 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Thu, 19 Nov 2026 22:49:49 +0000 Subject: [PATCH 1/4] fix(a11y): add screen-reader headings for WCAG 2.4.6 (headings and labels) Give Home, Explore, Dashboard and Chart Creation a level-one page heading, and label the dashboard filter bar and content area with level-two section headings, through a shared VisuallyHidden component with an `as` prop. Chart Creation promotes its visible title from h3 to h1 instead of adding a hidden duplicate. The Filters heading renders once per orientation and not when the filter bar is hidden (report mode). Co-authored-by: Fedo Hagge-Kubat Co-Authored-By: Claude Opus 5.5 --- .../Accessibility/VisuallyHidden.test.tsx | 55 ++++++++++++++ .../Accessibility/VisuallyHidden.tsx | 60 +++++++++++++++ .../src/components/Accessibility/index.tsx | 22 ++++++ .../DashboardBuilder.test.tsx | 76 +++++++++++++++++++ .../DashboardBuilder/DashboardBuilder.tsx | 8 ++ .../components/Header/Header.test.tsx | 7 ++ .../src/dashboard/components/Header/index.tsx | 4 + .../ExploreChartHeader.test.tsx | 11 +++ .../components/ExploreChartHeader/index.tsx | 2 + .../src/pages/Chart/Chart.test.tsx | 12 ++- .../ChartCreation/ChartCreation.test.tsx | 7 ++ .../src/pages/ChartCreation/index.tsx | 6 +- .../src/pages/Home/Home.test.tsx | 7 ++ superset-frontend/src/pages/Home/index.tsx | 2 + 14 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 superset-frontend/src/components/Accessibility/VisuallyHidden.test.tsx create mode 100644 superset-frontend/src/components/Accessibility/VisuallyHidden.tsx create mode 100644 superset-frontend/src/components/Accessibility/index.tsx diff --git a/superset-frontend/src/components/Accessibility/VisuallyHidden.test.tsx b/superset-frontend/src/components/Accessibility/VisuallyHidden.test.tsx new file mode 100644 index 000000000000..ccc0e03efdc2 --- /dev/null +++ b/superset-frontend/src/components/Accessibility/VisuallyHidden.test.tsx @@ -0,0 +1,55 @@ +/** + * 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 { render, screen } from 'spec/helpers/testing-library'; +import VisuallyHidden from './VisuallyHidden'; + +test('renders children', () => { + render(Screen-reader only text); + expect(screen.getByText('Screen-reader only text')).toBeInTheDocument(); +}); + +test('renders as span by default', () => { + render(Default tag); + const el = screen.getByText('Default tag'); + expect(el.tagName).toBe('SPAN'); +}); + +test('renders as a custom element when as prop is provided', () => { + render(Page heading); + const el = screen.getByText('Page heading'); + expect(el.tagName).toBe('H1'); +}); + +test('forwards id and className props', () => { + render( + + Text + , + ); + const el = screen.getByText('Text'); + expect(el).toHaveAttribute('id', 'my-id'); + expect(el).toHaveClass('my-class'); +}); + +test('applies clip-rect style for screen-reader-only behavior', () => { + render(Hidden); + const el = screen.getByText('Hidden'); + expect(el).toHaveStyle({ position: 'absolute' }); + expect(el).toHaveStyle({ clip: 'rect(0, 0, 0, 0)' }); +}); diff --git a/superset-frontend/src/components/Accessibility/VisuallyHidden.tsx b/superset-frontend/src/components/Accessibility/VisuallyHidden.tsx new file mode 100644 index 000000000000..c827bb9dbce5 --- /dev/null +++ b/superset-frontend/src/components/Accessibility/VisuallyHidden.tsx @@ -0,0 +1,60 @@ +/** + * 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 { ElementType, FC, ReactNode } from 'react'; +import { styled } from '@apache-superset/core/theme'; + +/** + * VisuallyHidden — content that is available to assistive technology but not + * visually rendered. Use for screen-reader-only headings, labels, and live + * regions where a duplicate visible element would be redundant. + * + * Renders a `` by default. Pass `as` to render a different element + * (e.g. `as="h1"` for an sr-only page heading). + */ +const HiddenElement = styled.span` + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; +`; + +export interface VisuallyHiddenProps { + /** Element type to render. Defaults to `'span'`. */ + as?: ElementType; + children?: ReactNode; + id?: string; + className?: string; +} + +const VisuallyHidden: FC = ({ + as = 'span', + children, + ...rest +}) => ( + + {children} + +); + +export default VisuallyHidden; diff --git a/superset-frontend/src/components/Accessibility/index.tsx b/superset-frontend/src/components/Accessibility/index.tsx new file mode 100644 index 000000000000..0a81b1e06f72 --- /dev/null +++ b/superset-frontend/src/components/Accessibility/index.tsx @@ -0,0 +1,22 @@ +/** + * 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. + */ +export { + default as VisuallyHidden, + type VisuallyHiddenProps, +} from './VisuallyHidden'; diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index cad8c7ca66ad..0f658ffe714d 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -1597,3 +1597,79 @@ test('restored dashboard hydration survives entering edit mode', async () => { )); } }); + +const renderWithFilterBar = (orientation: FilterBarOrientation) => { + const nativeFiltersSpy = jest + .spyOn(useNativeFiltersModule, 'useNativeFilters') + .mockReturnValue({ + showDashboard: true, + missingInitialFilters: [], + dashboardFiltersOpen: true, + toggleDashboardFiltersOpen: jest.fn(), + nativeFiltersEnabled: true, + hasFilters: true, + }); + (useStoredSidebarWidth as jest.Mock).mockImplementation(() => [ + 100, + jest.fn(), + ]); + (fetchFaveStar as jest.Mock).mockReturnValue({ type: 'mock-action' }); + (setActiveTab as jest.Mock).mockReturnValue({ type: 'mock-action' }); + const view = render(, { + useRedux: true, + store: storeWithState({ + ...mockState, + dashboardInfo: { + ...mockState.dashboardInfo, + filterBarOrientation: orientation, + }, + dashboardLayout: undoableDashboardLayout, + }), + useDnd: true, + useRouter: true, + useTheme: true, + }); + return { ...view, restore: () => nativeFiltersSpy.mockRestore() }; +}; + +test.each([FilterBarOrientation.Vertical, FilterBarOrientation.Horizontal])( + 'renders a single screen-reader Filters heading for the %s filter bar', + orientation => { + const { restore } = renderWithFilterBar(orientation); + try { + expect( + screen.getAllByRole('heading', { level: 2, name: 'Filters' }), + ).toHaveLength(1); + } finally { + restore(); + } + }, +); + +test.each([FilterBarOrientation.Vertical, FilterBarOrientation.Horizontal])( + 'renders no Filters heading for the hidden %s filter bar in report mode', + orientation => { + const originalHref = window.location.href; + window.history.replaceState({}, '', '/?standalone=3'); + const { restore } = renderWithFilterBar(orientation); + try { + expect( + screen.queryByRole('heading', { level: 2, name: 'Filters' }), + ).not.toBeInTheDocument(); + } finally { + restore(); + window.history.replaceState({}, '', originalHref); + } + }, +); + +test('renders a screen-reader heading for the dashboard content', () => { + const { restore } = renderWithFilterBar(FilterBarOrientation.Vertical); + try { + expect( + screen.getByRole('heading', { level: 2, name: 'Dashboard content' }), + ).toBeInTheDocument(); + } finally { + restore(); + } +}); diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx index 61cf70f88bfc..eefaac2df710 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -40,6 +40,7 @@ import { css, styled, useTheme } from '@apache-superset/core/theme'; import { useDispatch, useSelector } from 'react-redux'; import { Drawer, EmptyState, Loading } from '@superset-ui/core/components'; import { ErrorBoundary, BasicErrorAlert } from 'src/components'; +import { VisuallyHidden } from 'src/components/Accessibility'; import BuilderComponentPane from 'src/dashboard/components/BuilderComponentPane'; import DashboardHeader from 'src/dashboard/components/Header'; import HeadlessAutoRefresh from 'src/dashboard/components/Header/HeadlessAutoRefresh'; @@ -767,6 +768,11 @@ const DashboardBuilder = () => { so it must never start a refresh timer that could re-fetch charts mid-capture. */} {hideDashboardHeader && !isReport && } + {showFilterBar && + filterBarOrientation === FilterBarOrientation.Horizontal && + !hideFilterBar && ( + {t('Filters')} + )} {showFilterBar && filterBarOrientation === FilterBarOrientation.Horizontal && ( { hidden={hideFilterBar} data-test="dashboard-filters-panel" > + {t('Filters')}
{ )} + {t('Dashboard content')} { ); }); +test('should render the title as a screen-reader page heading', () => { + setup(); + expect( + screen.getByRole('heading', { level: 1, name: 'Dashboard Title' }), + ).toBeInTheDocument(); +}); + test('should render the editable title', () => { setup(editableState); expect(screen.getByDisplayValue('Dashboard Title')).toBeInTheDocument(); diff --git a/superset-frontend/src/dashboard/components/Header/index.tsx b/superset-frontend/src/dashboard/components/Header/index.tsx index 941ea2d099ca..9ecded6d6aa2 100644 --- a/superset-frontend/src/dashboard/components/Header/index.tsx +++ b/superset-frontend/src/dashboard/components/Header/index.tsx @@ -33,6 +33,7 @@ import { t } from '@apache-superset/core/translation'; import { Global } from '@emotion/react'; import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { bindActionCreators } from 'redux'; +import { VisuallyHidden } from 'src/components/Accessibility'; import { LOG_ACTIONS_TOGGLE_EDIT_DASHBOARD } from 'src/logger/LogUtils'; import { Icons } from '@superset-ui/core/components/Icons'; import { @@ -862,6 +863,9 @@ const Header = ({ onOpenMobileFilters }: HeaderComponentProps): JSX.Element => { data-test-id={dashboardInfo.id} className="dashboard-header-container" > + + {dashboardTitle || t('Dashboard')} + { expect(await screen.findByText('2 days ago')).toBeInTheDocument(); }); + test('renders the chart name as a screen-reader page heading', async () => { + const props = createProps(); + render(, { useRedux: true }); + expect( + await screen.findByRole('heading', { + level: 1, + name: 'Age distribution of respondents', + }), + ).toBeInTheDocument(); + }); + test('Changes "Added to X dashboards" to plural when more than 1 dashboard', async () => { const props = createProps({ showTitlePanelItems: true }); render( diff --git a/superset-frontend/src/explore/components/ExploreChartHeader/index.tsx b/superset-frontend/src/explore/components/ExploreChartHeader/index.tsx index 78b73224c45e..18074776664f 100644 --- a/superset-frontend/src/explore/components/ExploreChartHeader/index.tsx +++ b/superset-frontend/src/explore/components/ExploreChartHeader/index.tsx @@ -27,6 +27,7 @@ import { UnsavedChangesModal, } from '@superset-ui/core/components'; import { AlteredSliceTag } from 'src/components'; +import { VisuallyHidden } from 'src/components/Accessibility'; import { QueryFormData, JsonObject, @@ -415,6 +416,7 @@ const ExploreChartHeader: FC = ({ return ( <> + {sliceName || t('Explore chart')} { url: 'chartid', }, }); - const { getByTestId, getByText } = render(, { + const { getByTestId, getAllByText } = render(, { useRouter: true, useRedux: true, useDnd: true, @@ -184,7 +184,9 @@ describe('ChartPage', () => { expect(getByTestId('mock-explore-chart-panel')).toHaveTextContent( 'is_access_denial', ); - expect(getByText(expectedChartName)).toBeInTheDocument(); + // The chart name also renders in a screen-reader-only page heading + // (WCAG 2.4.6), so it is expected to appear more than once. + expect(getAllByText(expectedChartName).length).toBeGreaterThan(0); }); test('keeps the request-access path for an API that predates is_access_denial', async () => { @@ -218,7 +220,7 @@ describe('ChartPage', () => { url: 'chartid', }, }); - const { getByTestId, getByText } = render(, { + const { getByTestId, getAllByText } = render(, { useRouter: true, useRedux: true, useDnd: true, @@ -227,7 +229,9 @@ describe('ChartPage', () => { () => expect(fetchMock.callHistory.calls(chartApiRoute).length).toBe(1), { timeout: 5000 }, ); - expect(getByText(expectedChartName)).toBeInTheDocument(); + // The chart name also renders in a screen-reader-only page heading + // (WCAG 2.4.6), so it is expected to appear more than once. + expect(getAllByText(expectedChartName).length).toBeGreaterThan(0); // the legacy payload still must not name the dataset in Explore's state expect(getByTestId('mock-explore-chart-panel')).not.toHaveTextContent( 'Quarterly Sales', diff --git a/superset-frontend/src/pages/ChartCreation/ChartCreation.test.tsx b/superset-frontend/src/pages/ChartCreation/ChartCreation.test.tsx index fac3275da41f..2b559a9da4cf 100644 --- a/superset-frontend/src/pages/ChartCreation/ChartCreation.test.tsx +++ b/superset-frontend/src/pages/ChartCreation/ChartCreation.test.tsx @@ -819,3 +819,10 @@ test('shows a danger toast and leaves the selection empty on a forbidden respons locationSpy.mockRestore(); }); + +test('renders the page title as the level-one heading', async () => { + await renderComponent(); + expect( + screen.getByRole('heading', { level: 1, name: 'Create a new chart' }), + ).toBeInTheDocument(); +}); diff --git a/superset-frontend/src/pages/ChartCreation/index.tsx b/superset-frontend/src/pages/ChartCreation/index.tsx index e8edd9239c2c..1bcc8cf57725 100644 --- a/superset-frontend/src/pages/ChartCreation/index.tsx +++ b/superset-frontend/src/pages/ChartCreation/index.tsx @@ -100,8 +100,10 @@ const StyledContainer = styled.div` padding-right: ${theme.padding}px; padding-bottom: ${theme.padding}px; - h3 { + h1 { padding-bottom: ${theme.paddingSM}px; + margin: ${theme.marginMD}px 0; + font-size: ${theme.fontSizeLG}px; } & .dataset { @@ -394,7 +396,7 @@ export const ChartCreation = ({ user }: ChartCreationProps) => { return ( -

{t('Create a new chart')}

+

{t('Create a new chart')}

{ + await renderWelcome(); + expect( + screen.getByRole('heading', { level: 1, name: 'Home' }), + ).toBeInTheDocument(); +}); diff --git a/superset-frontend/src/pages/Home/index.tsx b/superset-frontend/src/pages/Home/index.tsx index 82ff403b81e2..71dbc52c9653 100644 --- a/superset-frontend/src/pages/Home/index.tsx +++ b/superset-frontend/src/pages/Home/index.tsx @@ -52,6 +52,7 @@ import { redirect } from 'src/utils/navigationUtils'; import { RoutePaths } from 'src/views/routePaths'; import { TableTab } from 'src/views/CRUD/types'; import SubMenu, { SubMenuProps } from 'src/features/home/SubMenu'; +import { VisuallyHidden } from 'src/components/Accessibility'; import { userHasPermission } from 'src/dashboard/util/permissionUtils'; import { WelcomePageLastTab } from 'src/features/home/types'; import ActivityTable from 'src/features/home/ActivityTable'; @@ -354,6 +355,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) { )} + {t('Home')} {WelcomeMessageExtension && } {WelcomeTopExtension && } {WelcomeMainExtension && } From 04a8629e332471cc3901aa217016e3e4b6c035e4 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Fri, 20 Nov 2026 00:47:16 +0000 Subject: [PATCH 2/4] chore(i18n): add new heading strings to messages.pot Co-Authored-By: Claude Sonnet 5.5 --- superset/translations/messages.pot | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/superset/translations/messages.pot b/superset/translations/messages.pot index e5ecf62e71da..26980461875c 100644 --- a/superset/translations/messages.pot +++ b/superset/translations/messages.pot @@ -4793,6 +4793,9 @@ msgstr "" msgid "Dashboard color configuration could not be updated." msgstr "" +msgid "Dashboard content" +msgstr "" + msgid "Dashboard could not be deleted." msgstr "" @@ -6776,6 +6779,9 @@ msgstr "" msgid "Explore - %(table)s" msgstr "" +msgid "Explore chart" +msgstr "" + msgid "Explore the result set in the data exploration view" msgstr "" From a1801844fab20eec995aea698e423a9af822c96b Mon Sep 17 00:00:00 2001 From: Joe Li Date: Sat, 21 Nov 2026 17:47:00 +0000 Subject: [PATCH 3/4] fix(a11y): keep h3 padding in chart creation and tighten title assertions Co-Authored-By: Claude Sonnet 5.5 --- superset-frontend/src/pages/Chart/Chart.test.tsx | 12 ++++++------ superset-frontend/src/pages/ChartCreation/index.tsx | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/pages/Chart/Chart.test.tsx b/superset-frontend/src/pages/Chart/Chart.test.tsx index f99d749bfcea..80fe7f2042f0 100644 --- a/superset-frontend/src/pages/Chart/Chart.test.tsx +++ b/superset-frontend/src/pages/Chart/Chart.test.tsx @@ -184,9 +184,9 @@ describe('ChartPage', () => { expect(getByTestId('mock-explore-chart-panel')).toHaveTextContent( 'is_access_denial', ); - // The chart name also renders in a screen-reader-only page heading - // (WCAG 2.4.6), so it is expected to appear more than once. - expect(getAllByText(expectedChartName).length).toBeGreaterThan(0); + // The chart name renders in the editable title and in the + // screen-reader-only page heading (WCAG 2.4.6). + expect(getAllByText(expectedChartName)).toHaveLength(2); }); test('keeps the request-access path for an API that predates is_access_denial', async () => { @@ -229,9 +229,9 @@ describe('ChartPage', () => { () => expect(fetchMock.callHistory.calls(chartApiRoute).length).toBe(1), { timeout: 5000 }, ); - // The chart name also renders in a screen-reader-only page heading - // (WCAG 2.4.6), so it is expected to appear more than once. - expect(getAllByText(expectedChartName).length).toBeGreaterThan(0); + // The chart name renders in the editable title and in the + // screen-reader-only page heading (WCAG 2.4.6). + expect(getAllByText(expectedChartName)).toHaveLength(2); // the legacy payload still must not name the dataset in Explore's state expect(getByTestId('mock-explore-chart-panel')).not.toHaveTextContent( 'Quarterly Sales', diff --git a/superset-frontend/src/pages/ChartCreation/index.tsx b/superset-frontend/src/pages/ChartCreation/index.tsx index e027feddb789..40074b80a52c 100644 --- a/superset-frontend/src/pages/ChartCreation/index.tsx +++ b/superset-frontend/src/pages/ChartCreation/index.tsx @@ -102,8 +102,12 @@ const StyledContainer = styled.div` padding-right: ${theme.padding}px; padding-bottom: ${theme.padding}px; - h1 { + h1, + h3 { padding-bottom: ${theme.paddingSM}px; + } + + h1 { margin: ${theme.marginMD}px 0; font-size: ${theme.fontSizeLG}px; } From 7440cc467763956f50046256375889a9a1e14c21 Mon Sep 17 00:00:00 2001 From: Joe Li Date: Wed, 25 Nov 2026 21:46:59 +0000 Subject: [PATCH 4/4] fix(dashboard): render the displayed (localized) title in the page heading Co-Authored-By: Claude Sonnet 5.5 --- .../src/dashboard/components/Header/Header.test.tsx | 9 +++++++-- .../src/dashboard/components/Header/index.tsx | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index a55e62d86287..739ecdb163f6 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -1445,7 +1445,10 @@ test('shows the localized title while it still names the current title', () => { }, }); - expect(screen.getByText('Tableau de bord')).toBeInTheDocument(); + expect(screen.getAllByText('Tableau de bord').length).toBeGreaterThan(0); + expect( + screen.getByRole('heading', { level: 1, name: 'Tableau de bord' }), + ).toBeInTheDocument(); expect(screen.queryByText('Dashboard Title')).not.toBeInTheDocument(); }); @@ -1461,7 +1464,9 @@ test('falls back to the canonical title once a rename outdates the translation', }, }); - expect(screen.getByText('Dashboard Title')).toBeInTheDocument(); + expect( + screen.getByRole('heading', { level: 1, name: 'Dashboard Title' }), + ).toBeInTheDocument(); expect(screen.queryByText('Tableau de bord')).not.toBeInTheDocument(); }); diff --git a/superset-frontend/src/dashboard/components/Header/index.tsx b/superset-frontend/src/dashboard/components/Header/index.tsx index afae9131fbca..0fff430f66e1 100644 --- a/superset-frontend/src/dashboard/components/Header/index.tsx +++ b/superset-frontend/src/dashboard/components/Header/index.tsx @@ -883,7 +883,7 @@ const Header = ({ onOpenMobileFilters }: HeaderComponentProps): JSX.Element => { className="dashboard-header-container" > - {dashboardTitle || t('Dashboard')} + {editableTitleProps.title || t('Dashboard')}