This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
feat(AccessibilityBehaviors): Define types for accessibility behaviors #1481
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
16b6eeb
feat(AccessibilityBehaviors): Define types for accessibility behavior…
762fd27
Small improvements
f804a6e
Fix tests
97db5c2
Merge branch 'master' into feat/acc-behaviors-add-typings-props
7344752
small improvement
be3003e
Improvements after CR comments
7fa9e92
fix test
ab46dcf
Merge branch 'master' into feat/acc-behaviors-add-typings-props
sophieH29 7fd40df
update changelog
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
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
15 changes: 9 additions & 6 deletions
15
packages/react/src/lib/accessibility/Behaviors/Button/buttonBehavior.ts
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,21 +1,24 @@ | ||
| import { Accessibility } from '../../types' | ||
| import * as _ from 'lodash' | ||
|
|
||
| /** | ||
| * @specification | ||
| * Adds role='button' if element type is other than 'button'. This allows screen readers to handle the component as a button. | ||
| * Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component. | ||
| */ | ||
|
|
||
| const buttonBehavior: Accessibility = (props: any) => ({ | ||
| const buttonBehavior: Accessibility<ButtonBehaviorProps> = props => ({ | ||
| attributes: { | ||
| root: { | ||
| role: props.as === 'button' ? undefined : 'button', | ||
| 'aria-disabled': !_.isNil(props['aria-disabled']) | ||
| ? props['aria-disabled'] | ||
| : !!props['disabled'], | ||
| 'aria-disabled': props.disabled, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| export default buttonBehavior | ||
|
|
||
| export type ButtonBehaviorProps = { | ||
| /** Element type. */ | ||
| as: string | ||
| /** A button can show it is currently unable to be interacted with. */ | ||
| disabled?: boolean | ||
| } |
16 changes: 9 additions & 7 deletions
16
packages/react/src/lib/accessibility/Behaviors/Button/toggleButtonBehavior.ts
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,23 +1,25 @@ | ||
| import { Accessibility } from '../../types' | ||
| import * as _ from 'lodash' | ||
| import { ButtonBehaviorProps } from './buttonBehavior' | ||
|
|
||
| /** | ||
| * @specification | ||
| * Adds role='button' if element type is other than 'button'. This allows screen readers to handle the component as a button | ||
| * Adds attribute 'aria-pressed=true' based on the property 'active'. This can be overriden by providing 'aria-presssed' property directly to the component. | ||
| * Adds attribute 'aria-disabled=true' based on the property 'disabled'. This can be overriden by providing 'aria-disabled' property directly to the component. | ||
| */ | ||
|
|
||
| const toggleButtonBehavior: Accessibility = (props: any) => ({ | ||
| const toggleButtonBehavior: Accessibility<ToggleButtonBehaviorProps> = props => ({ | ||
| attributes: { | ||
| root: { | ||
| role: props.as === 'button' ? undefined : 'button', | ||
| 'aria-disabled': !_.isNil(props['aria-disabled']) | ||
| ? props['aria-disabled'] | ||
| : !!props['disabled'], | ||
| 'aria-pressed': !_.isNil(props['aria-presssed']) ? props['aria-presssed'] : !!props['active'], | ||
| 'aria-disabled': props.disabled, | ||
| 'aria-pressed': !!props.active, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| export default toggleButtonBehavior | ||
|
|
||
| type ToggleButtonBehaviorProps = ButtonBehaviorProps & { | ||
| /** Indicates if a button is in pressed state. */ | ||
| active: boolean | ||
| } |
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
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.
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.