Repository navigation
fix(a11y): add screen-reader headings for WCAG 2.4.6 (headings and labels) #46395
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
Open
sadpandajoe
wants to merge
7
commits into
master
Choose a base branch
from
ultraset-descriptive-page-headings-section-labels
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+289
−7
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
98b273c
fix(a11y): add screen-reader headings for WCAG 2.4.6 (headings and la…
sadpandajoe 04a8629
chore(i18n): add new heading strings to messages.pot
sadpandajoe 532e879
chore: merge master into ultraset-descriptive-page-headings-section-l…
sadpandajoe a180184
fix(a11y): keep h3 padding in chart creation and tighten title assert…
sadpandajoe ddcfe71
Merge branch 'master' into ultraset-descriptive-page-headings-section…
sadpandajoe 7440cc4
fix(dashboard): render the displayed (localized) title in the page he…
sadpandajoe 71e5709
Merge remote-tracking branch 'origin/master' into ultraset-descriptiv…
sadpandajoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
superset-frontend/src/components/Accessibility/VisuallyHidden.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(<VisuallyHidden>Screen-reader only text</VisuallyHidden>); | ||
| expect(screen.getByText('Screen-reader only text')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('renders as span by default', () => { | ||
| render(<VisuallyHidden>Default tag</VisuallyHidden>); | ||
| const el = screen.getByText('Default tag'); | ||
| expect(el.tagName).toBe('SPAN'); | ||
| }); | ||
|
|
||
| test('renders as a custom element when as prop is provided', () => { | ||
| render(<VisuallyHidden as="h1">Page heading</VisuallyHidden>); | ||
| const el = screen.getByText('Page heading'); | ||
| expect(el.tagName).toBe('H1'); | ||
| }); | ||
|
|
||
| test('forwards id and className props', () => { | ||
| render( | ||
| <VisuallyHidden id="my-id" className="my-class"> | ||
| Text | ||
| </VisuallyHidden>, | ||
| ); | ||
| 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(<VisuallyHidden>Hidden</VisuallyHidden>); | ||
| const el = screen.getByText('Hidden'); | ||
| expect(el).toHaveStyle({ position: 'absolute' }); | ||
| expect(el).toHaveStyle({ clip: 'rect(0, 0, 0, 0)' }); | ||
| }); |
60 changes: 60 additions & 0 deletions
60
superset-frontend/src/components/Accessibility/VisuallyHidden.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 `<span>` 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<VisuallyHiddenProps> = ({ | ||
| as = 'span', | ||
| children, | ||
| ...rest | ||
| }) => ( | ||
| <HiddenElement as={as} {...rest}> | ||
| {children} | ||
| </HiddenElement> | ||
| ); | ||
|
|
||
| export default VisuallyHidden; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.