Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit df26fa6

Browse files
authored
feat(mixed): add accessibility prop to all components (#927)
* fix(mixed): add `accessibility` prop to all components * use factory * fix lint issues * fix propTypes * update behavior * add changelog entry
1 parent f979147 commit df26fa6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+208
-43
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2323
- Add basic animation library for Teams theme @bhamlefty @mnajdova ([#871](https://github.com/stardust-ui/react/pull/871)
2424
- Export `accept` and `urgent` SVG icons to the Teams Theme @joheredi([#929](https://github.com/stardust-ui/react/pull/929))
2525
- Add `open`, `defaultOpen` and `onOpenChange` props for `Dropdown` component (controlled mode) @Bugaa92 ([#900](https://github.com/stardust-ui/react/pull/900))
26+
- Add `accessibility` prop to all components that supports it @layershifter ([#927](https://github.com/stardust-ui/react/pull/927))
2627

2728
### Fixes
2829
- Display correctly images in portrait mode inside `Avatar` @layershifter ([#899](https://github.com/stardust-ui/react/pull/899))

packages/react/src/components/Accordion/Accordion.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ class Accordion extends AutoControlledComponent<ReactProps<AccordionProps>, any>
104104
}),
105105
),
106106
]),
107-
accessibility: PropTypes.func,
108107

109108
renderPanelTitle: PropTypes.func,
110109
renderPanelContent: PropTypes.func,

packages/react/src/components/Animation/Animation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class Animation extends UIComponent<ReactPropsStrict<AnimationProps>, any> {
9191

9292
static propTypes = {
9393
...commonPropTypes.createCommon({
94+
accessibility: false,
9495
animated: false,
9596
content: false,
9697
children: 'element',

packages/react/src/components/Attachment/Attachment.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class Attachment extends UIComponent<ReactProps<AttachmentProps>, AttachmentStat
7575
...commonPropTypes.createCommon({
7676
content: false,
7777
}),
78-
accessibility: PropTypes.func,
7978
action: customPropTypes.itemShorthand,
8079
actionable: PropTypes.bool,
8180
description: customPropTypes.itemShorthand,

packages/react/src/components/Avatar/Avatar.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as React from 'react'
33
import Image from '../Image/Image'
44
import Label from '../Label/Label'
55
import Status, { StatusProps } from '../Status/Status'
6+
import { Accessibility } from '../../lib/accessibility/types'
7+
import { defaultBehavior } from '../../lib/accessibility'
68
import { ReactProps, ShorthandValue } from '../../types'
79
import {
810
createShorthandFactory,
@@ -14,6 +16,12 @@ import {
1416
} from '../../lib'
1517

1618
export interface AvatarProps extends UIComponentProps {
19+
/**
20+
* Accessibility behavior if overridden by the user.
21+
* @default defaultBehavior
22+
*/
23+
accessibility?: Accessibility
24+
1725
/** Shorthand for the image. */
1826
image?: ShorthandValue
1927

@@ -57,6 +65,7 @@ class Avatar extends UIComponent<ReactProps<AvatarProps>, any> {
5765
}
5866

5967
static defaultProps = {
68+
accessibility: defaultBehavior,
6069
size: 'medium',
6170
getInitials(name: string) {
6271
if (!name) {
@@ -81,11 +90,11 @@ class Avatar extends UIComponent<ReactProps<AvatarProps>, any> {
8190
},
8291
} as AvatarProps
8392

84-
renderComponent({ ElementType, classes, unhandledProps, styles, variables }) {
93+
renderComponent({ accessibility, ElementType, classes, unhandledProps, styles, variables }) {
8594
const { name, status, image, label, getInitials, size } = this.props as AvatarProps
8695

8796
return (
88-
<ElementType {...unhandledProps} className={classes.root}>
97+
<ElementType {...accessibility.attributes.root} {...unhandledProps} className={classes.root}>
8998
{Image.create(image, {
9099
defaultProps: {
91100
fluid: true,

packages/react/src/components/Button/Button.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ class Button extends UIComponent<ReactProps<ButtonProps>, ButtonState> {
106106
primary: customPropTypes.every([customPropTypes.disallow(['secondary']), PropTypes.bool]),
107107
text: PropTypes.bool,
108108
secondary: customPropTypes.every([customPropTypes.disallow(['primary']), PropTypes.bool]),
109-
accessibility: PropTypes.func,
110109
}
111110

112111
public static defaultProps = {

packages/react/src/components/Button/ButtonGroup.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ import {
1313
commonPropTypes,
1414
rtlTextContainer,
1515
} from '../../lib'
16+
import { Accessibility } from '../../lib/accessibility/types'
17+
import { defaultBehavior } from '../../lib/accessibility'
1618
import Button from './Button'
1719

1820
export interface ButtonGroupProps
1921
extends UIComponentProps,
2022
ChildrenComponentProps,
2123
ContentComponentProps {
24+
/**
25+
* Accessibility behavior if overridden by the user.
26+
* @default defaultBehavior
27+
*/
28+
accessibility?: Accessibility
29+
2230
/** The buttons contained inside the ButtonGroup. */
2331
buttons?: ShorthandValue[]
2432

@@ -36,12 +44,12 @@ class ButtonGroup extends UIComponent<ReactProps<ButtonGroupProps>, any> {
3644

3745
public static propTypes = {
3846
...commonPropTypes.createCommon(),
39-
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
4047
buttons: customPropTypes.collectionShorthand,
4148
circular: PropTypes.bool,
4249
}
4350

4451
public static defaultProps = {
52+
accessibility: defaultBehavior,
4553
as: 'div',
4654
}
4755

packages/react/src/components/Chat/Chat.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class Chat extends UIComponent<ReactProps<ChatProps>, any> {
3939
...commonPropTypes.createCommon({
4040
content: false,
4141
}),
42-
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
4342
items: PropTypes.arrayOf(customPropTypes.itemShorthand),
4443
}
4544

packages/react/src/components/Chat/ChatItem.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
rtlTextContainer,
1515
} from '../../lib'
1616
import Box from '../Box/Box'
17+
import { Accessibility } from '../../lib/accessibility/types'
18+
import { defaultBehavior } from '../../lib/accessibility'
1719
import { ComponentSlotStylesPrepared } from '../../themes/types'
1820

1921
export interface ChatItemSlotClassNames {
@@ -22,6 +24,12 @@ export interface ChatItemSlotClassNames {
2224
}
2325

2426
export interface ChatItemProps extends UIComponentProps, ChildrenComponentProps {
27+
/**
28+
* Accessibility behavior if overridden by the user.
29+
* @default defaultBehavior
30+
*/
31+
accessibility?: Accessibility
32+
2533
/** Controls item's relation to other chat items. */
2634
attached?: boolean | 'top' | 'bottom'
2735

@@ -53,12 +61,14 @@ class ChatItem extends UIComponent<ReactProps<ChatItemProps>, any> {
5361
}
5462

5563
static defaultProps = {
64+
accessibility: defaultBehavior,
5665
as: 'li',
5766
contentPosition: 'start',
5867
attached: false,
5968
}
6069

6170
renderComponent({
71+
accessibility,
6272
ElementType,
6373
classes,
6474
unhandledProps,
@@ -69,6 +79,7 @@ class ChatItem extends UIComponent<ReactProps<ChatItemProps>, any> {
6979
return (
7080
<ElementType
7181
{...rtlTextContainer.getAttributes({ forElements: [children] })}
82+
{...accessibility.attributes.root}
7283
{...unhandledProps}
7384
className={classes.root}
7485
>

packages/react/src/components/Chat/ChatMessage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ class ChatMessage extends UIComponent<ReactProps<ChatMessageProps>, ChatMessageS
9696

9797
static propTypes = {
9898
...commonPropTypes.createCommon({ content: 'shorthand' }),
99-
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
10099
actionMenu: customPropTypes.itemShorthand,
101100
author: customPropTypes.itemShorthand,
102101
badge: customPropTypes.itemShorthand,

packages/react/src/components/Dialog/Dialog.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ class Dialog extends AutoControlledComponent<ReactProps<DialogProps>, DialogStat
9494
content: true,
9595
}),
9696
actions: customPropTypes.itemShorthand,
97-
accessibility: PropTypes.func,
9897
cancelButton: customPropTypes.itemShorthand,
9998
confirmButton: customPropTypes.itemShorthand,
10099
defaultOpen: PropTypes.bool,

packages/react/src/components/Divider/Divider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ import {
1212
commonPropTypes,
1313
rtlTextContainer,
1414
} from '../../lib'
15+
import { Accessibility } from '../../lib/accessibility/types'
16+
import { defaultBehavior } from '../../lib/accessibility'
1517
import { ReactProps } from '../../types'
1618

1719
export interface DividerProps
1820
extends UIComponentProps,
1921
ChildrenComponentProps,
2022
ColorComponentProps,
2123
ContentComponentProps {
24+
/**
25+
* Accessibility behavior if overridden by the user.
26+
* @default defaultBehavior
27+
*/
28+
accessibility?: Accessibility
29+
2230
/** A divider can be fitted, without any space above or below it. */
2331
fitted?: boolean
2432

@@ -47,15 +55,17 @@ class Divider extends UIComponent<ReactProps<DividerProps>, any> {
4755
}
4856

4957
static defaultProps = {
58+
accessibility: defaultBehavior,
5059
size: 0,
5160
}
5261

53-
renderComponent({ ElementType, classes, unhandledProps }) {
62+
renderComponent({ accessibility, ElementType, classes, unhandledProps }) {
5463
const { children, content } = this.props
5564

5665
return (
5766
<ElementType
5867
{...rtlTextContainer.getAttributes({ forElements: [children, content] })}
68+
{...accessibility.attributes.root}
5969
{...unhandledProps}
6070
className={classes.root}
6171
>

packages/react/src/components/Dropdown/Dropdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo
210210

211211
static propTypes = {
212212
...commonPropTypes.createCommon({
213+
accessibility: false,
213214
children: false,
214215
content: false,
215216
}),

packages/react/src/components/Dropdown/DropdownItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class DropdownItem extends UIComponent<ReactProps<DropdownItemProps>, any> {
4949

5050
static propTypes = {
5151
...commonPropTypes.createCommon({
52+
accessibility: false,
5253
children: false,
5354
content: false,
5455
}),

packages/react/src/components/Dropdown/DropdownSearchInput.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class DropdownSearchInput extends UIComponent<ReactProps<DropdownSearchInputProp
6868

6969
static propTypes = {
7070
...commonPropTypes.createCommon({
71+
accessibility: false,
7172
children: false,
7273
content: false,
7374
}),

packages/react/src/components/Dropdown/DropdownSelectedItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class DropdownSelectedItem extends UIComponent<ReactProps<DropdownSelectedItemPr
7272

7373
static propTypes = {
7474
...commonPropTypes.createCommon({
75+
accessibility: false,
7576
children: false,
7677
}),
7778
active: PropTypes.bool,

packages/react/src/components/Flex/Flex.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Flex extends UIComponent<ReactProps<FlexProps>> {
5757

5858
public static propTypes = {
5959
...commonPropTypes.createCommon({
60+
accessibility: false,
6061
content: false,
6162
}),
6263

packages/react/src/components/Flex/FlexItem.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FlexItem extends UIComponent<Extendable<FlexItemProps>> {
4343

4444
static propTypes = {
4545
...commonPropTypes.createCommon({
46+
accessibility: false,
4647
content: false,
4748
}),
4849
align: PropTypes.oneOf(['auto', 'start', 'end', 'center', 'baseline', 'stretch']),

packages/react/src/components/Form/Form.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ import {
1111
commonPropTypes,
1212
rtlTextContainer,
1313
} from '../../lib'
14+
import { Accessibility } from '../../lib/accessibility/types'
15+
import { defaultBehavior } from '../../lib/accessibility'
1416
import { ComponentEventHandler, ReactProps, ShorthandValue } from '../../types'
1517
import FormField from './FormField'
1618

1719
export interface FormProps extends UIComponentProps, ChildrenComponentProps {
20+
/**
21+
* Accessibility behavior if overridden by the user.
22+
* @default defaultBehavior
23+
*/
24+
accessibility?: Accessibility
25+
1826
/** The HTML form action. */
1927
action?: string
2028

@@ -51,19 +59,21 @@ class Form extends UIComponent<ReactProps<FormProps>, any> {
5159
}
5260

5361
public static defaultProps = {
62+
accessibility: defaultBehavior,
5463
as: 'form',
5564
}
5665

5766
public static Field = FormField
5867

59-
public renderComponent({ ElementType, classes, unhandledProps }): React.ReactNode {
68+
public renderComponent({ accessibility, ElementType, classes, unhandledProps }): React.ReactNode {
6069
const { action, children } = this.props
6170
return (
6271
<ElementType
6372
className={classes.root}
6473
action={action}
6574
onSubmit={this.handleSubmit}
6675
{...rtlTextContainer.getAttributes({ forElements: [children] })}
76+
{...accessibility.attributes.root}
6777
{...unhandledProps}
6878
>
6979
{childrenExist(children) ? children : this.renderFields()}

packages/react/src/components/Form/FormField.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,20 @@ import {
1010
ChildrenComponentProps,
1111
commonPropTypes,
1212
} from '../../lib'
13+
import { Accessibility } from '../../lib/accessibility/types'
14+
import { defaultBehavior } from '../../lib/accessibility'
1315
import { ReactProps, ShorthandValue } from '../../types'
1416
import Text from '../Text/Text'
1517
import Input from '../Input/Input'
1618
import Box from '../Box/Box'
1719

1820
export interface FormFieldProps extends UIComponentProps, ChildrenComponentProps {
21+
/**
22+
* Accessibility behavior if overridden by the user.
23+
* @default defaultBehavior
24+
*/
25+
accessibility?: Accessibility
26+
1927
/** A control for the form field. */
2028
control?: ShorthandValue
2129

@@ -66,6 +74,7 @@ class FormField extends UIComponent<ReactProps<FormFieldProps>, any> {
6674
}
6775

6876
public static defaultProps = {
77+
accessibility: defaultBehavior,
6978
as: 'div',
7079
control: { as: Input },
7180
}
@@ -108,7 +117,7 @@ class FormField extends UIComponent<ReactProps<FormFieldProps>, any> {
108117
)
109118

110119
return (
111-
<ElementType className={classes.root} {...unhandledProps}>
120+
<ElementType className={classes.root} {...accessibility.attributes.root} {...unhandledProps}>
112121
{childrenExist(children) ? children : content}
113122
</ElementType>
114123
)

packages/react/src/components/Grid/Grid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
4848
...commonPropTypes.createCommon({
4949
content: false,
5050
}),
51-
accessibility: PropTypes.func,
5251
columns: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
5352
content: customPropTypes.every([
5453
customPropTypes.disallow(['children']),
@@ -66,6 +65,7 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
6665
}
6766

6867
public renderComponent({
68+
accessibility,
6969
ElementType,
7070
classes,
7171
unhandledProps,
@@ -76,6 +76,7 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
7676
<ElementType
7777
className={classes.root}
7878
{...rtlTextContainer.getAttributes({ forElements: [children, content] })}
79+
{...accessibility.attributes.root}
7980
{...unhandledProps}
8081
>
8182
{childrenExist(children) ? children : content}

0 commit comments

Comments
 (0)