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,

0 commit comments

Comments
 (0)