-
Notifications
You must be signed in to change notification settings - Fork 61
feat(nav-tab): require aria-label(ledby) or label #748
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
nataliadelmar
wants to merge
2
commits into
momentum-design:master
Choose a base branch
from
nataliadelmar:NavTabLabel
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.
+140
−64
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,12 +14,14 @@ import './NavigationTab.style.scss'; | |
| const NavigationTab: FC<Props> = (props: Props) => { | ||
| const { icon, label, count = 0, className, id, size, style, active, ...otherProps } = props; | ||
|
|
||
| const isExpanded = size == 200; | ||
|
|
||
| const iconComponent = icon ? ( | ||
| <Icon className={STYLE.icon} name={icon} scale={24} weight={'filled'} strokeColor={'none'} /> | ||
| ) : null; | ||
|
|
||
| const labelComponent = | ||
| size == 200 && label ? ( | ||
| isExpanded && label ? ( | ||
| <Text className={STYLE.label} type="subheader-secondary" tagName="h3"> | ||
| {label} | ||
| </Text> | ||
|
|
@@ -45,6 +47,7 @@ const NavigationTab: FC<Props> = (props: Props) => { | |
| data-size={size || DEFAULTS.SIZE} | ||
| id={id} | ||
| style={style} | ||
| aria-label={isExpanded && label ? props['aria-label'] : props['aria-label'] || label} // if expanded with label, the accessible name will default to the visible label inside. | ||
|
Collaborator
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. I don't get what you're doing here
Collaborator
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. And you've not added any unit tests for it |
||
| {...otherProps} | ||
| > | ||
| {iconComponent} | ||
|
|
||
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 |
|---|---|---|
| @@ -1,47 +1,55 @@ | ||
| import { CSSProperties } from 'react'; | ||
| import { AriaButtonProps } from '@react-types/button'; | ||
| import { AriaLabelingProps } from '@react-types/shared'; | ||
| import { InferredIconName } from '../Icon/Icon.types'; | ||
|
|
||
| export interface Props extends AriaButtonProps { | ||
| /** | ||
| * Custom class for overriding this component's CSS. | ||
| */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| * Custom id for overriding this component's CSS. | ||
| */ | ||
| id?: string; | ||
|
|
||
| /** | ||
| * Custom style for overriding this component's CSS. | ||
| */ | ||
| style?: CSSProperties; | ||
|
|
||
| /** | ||
| * Size index of this NavTab. | ||
| */ | ||
| size?: number; | ||
|
|
||
| /** | ||
| * Size index of this NavTab. | ||
| */ | ||
| label?: string; | ||
|
|
||
| /** | ||
| * Size index of this NavTab. | ||
| */ | ||
| icon?: InferredIconName; | ||
|
|
||
| /** | ||
| * The amount inside the badge of components of this NavTab. If 0, then it is not shown. | ||
| */ | ||
| count?: number; | ||
|
|
||
| /** | ||
| * True if the tab is active. | ||
| */ | ||
| active?: boolean; | ||
| } | ||
| import { AriaLabelRequired } from '../../utils/a11y'; | ||
|
|
||
| export type Props = AriaButtonProps & | ||
| AriaLabelingProps & | ||
| ( | ||
| | { | ||
| /** | ||
| * Visible label for this tab | ||
| */ | ||
| label: string; | ||
| } | ||
| | ({ label?: never } & AriaLabelRequired) | ||
| ) & { | ||
| // if a label is not provided, an aria-label(lledby) is required | ||
| /** | ||
| * Custom class for overriding this component's CSS. | ||
| */ | ||
| className?: string; | ||
|
|
||
| /** | ||
| * Custom id for overriding this component's CSS. | ||
| */ | ||
| id?: string; | ||
|
|
||
| /** | ||
| * Custom style for overriding this component's CSS. | ||
| */ | ||
| style?: CSSProperties; | ||
|
|
||
| /** | ||
| * Size index of this NavTab. | ||
| */ | ||
| size?: number; | ||
|
|
||
| /** | ||
| * Size index of this NavTab. | ||
| */ | ||
| icon?: InferredIconName; | ||
|
|
||
| /** | ||
| * The amount inside the badge of components of this NavTab. If 0, then it is not shown. | ||
| */ | ||
| count?: number; | ||
|
|
||
| /** | ||
| * True if the tab is active. | ||
| */ | ||
| active?: boolean; | ||
| }; | ||
|
|
||
| export type NavTabSize = 40 | 48 | 200; |
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,10 @@ | ||
| import { Expect, ExpectExtends, ExpectFalse } from '../../utils/typetest.util'; | ||
| import { Props } from './NavigationTab.types'; | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| type cases = [ | ||
| Expect<ExpectExtends<Props, { 'aria-label': 'label' }>>, | ||
| Expect<ExpectExtends<Props, { 'aria-labelledby': 'some-label' }>>, | ||
| Expect<ExpectExtends<Props, { label: 'Some label' }>>, | ||
| ExpectFalse<ExpectExtends<Props, Record<string, never>>> | ||
| ]; |
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.
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.
I know this is a copy-paste, but I think our convention is always to use triple equals