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

feat(mixed): add accessibility prop to all components #927

Merged
merged 8 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add basic animation library for Teams theme @bhamlefty @mnajdova ([#871](https://github.com/stardust-ui/react/pull/871)
- Export `accept` and `urgent` SVG icons to the Teams Theme @joheredi([#929](https://github.com/stardust-ui/react/pull/929))
- Add `open`, `defaultOpen` and `onOpenChange` props for `Dropdown` component (controlled mode) @Bugaa92 ([#900](https://github.com/stardust-ui/react/pull/900))
- Add `accessibility` prop to all components that supports it @layershifter ([#927](https://github.com/stardust-ui/react/pull/927))

### Fixes
- Display correctly images in portrait mode inside `Avatar` @layershifter ([#899](https://github.com/stardust-ui/react/pull/899))
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class Accordion extends AutoControlledComponent<ReactProps<AccordionProps>, any>
}),
),
]),
accessibility: PropTypes.func,

renderPanelTitle: PropTypes.func,
renderPanelContent: PropTypes.func,
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Animation/Animation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class Animation extends UIComponent<ReactPropsStrict<AnimationProps>, any> {

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
animated: false,
content: false,
children: 'element',
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Attachment/Attachment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class Attachment extends UIComponent<ReactProps<AttachmentProps>, AttachmentStat
...commonPropTypes.createCommon({
content: false,
}),
accessibility: PropTypes.func,
action: customPropTypes.itemShorthand,
actionable: PropTypes.bool,
description: customPropTypes.itemShorthand,
Expand Down
13 changes: 11 additions & 2 deletions packages/react/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as React from 'react'
import Image from '../Image/Image'
import Label from '../Label/Label'
import Status, { StatusProps } from '../Status/Status'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import { ReactProps, ShorthandValue } from '../../types'
import {
createShorthandFactory,
Expand All @@ -14,6 +16,12 @@ import {
} from '../../lib'

export interface AvatarProps extends UIComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add this in interface (or if it should be use in all UI components, maybe even move to the UIComponentProps)? At least common interface would allow us to reuse the same description, although not sure how we can add different @defaults there..

Copy link
Contributor

@mnajdova mnajdova Feb 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw will we still need these @default description, after removing react-docgen-typescript? @kuzhelov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm note sure that the issues with @default will be solved right now while some components have different defaults 🐱


/** Shorthand for the image. */
image?: ShorthandValue

Expand Down Expand Up @@ -57,6 +65,7 @@ class Avatar extends UIComponent<ReactProps<AvatarProps>, any> {
}

static defaultProps = {
accessibility: defaultBehavior,
size: 'medium',
getInitials(name: string) {
if (!name) {
Expand All @@ -81,11 +90,11 @@ class Avatar extends UIComponent<ReactProps<AvatarProps>, any> {
},
} as AvatarProps

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

return (
<ElementType {...unhandledProps} className={classes.root}>
<ElementType {...accessibility.attributes.root} {...unhandledProps} className={classes.root}>
{Image.create(image, {
defaultProps: {
fluid: true,
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Button extends UIComponent<ReactProps<ButtonProps>, ButtonState> {
primary: customPropTypes.every([customPropTypes.disallow(['secondary']), PropTypes.bool]),
text: PropTypes.bool,
secondary: customPropTypes.every([customPropTypes.disallow(['primary']), PropTypes.bool]),
accessibility: PropTypes.func,
}

public static defaultProps = {
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/components/Button/ButtonGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ import {
commonPropTypes,
rtlTextContainer,
} from '../../lib'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import Button from './Button'

export interface ButtonGroupProps
extends UIComponentProps,
ChildrenComponentProps,
ContentComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility

/** The buttons contained inside the ButtonGroup. */
buttons?: ShorthandValue[]

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

public static propTypes = {
...commonPropTypes.createCommon(),
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
buttons: customPropTypes.collectionShorthand,
circular: PropTypes.bool,
}

public static defaultProps = {
accessibility: defaultBehavior,
as: 'div',
}

Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Chat extends UIComponent<ReactProps<ChatProps>, any> {
...commonPropTypes.createCommon({
content: false,
}),
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
items: PropTypes.arrayOf(customPropTypes.itemShorthand),
}

Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/components/Chat/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
rtlTextContainer,
} from '../../lib'
import Box from '../Box/Box'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import { ComponentSlotStylesPrepared } from '../../themes/types'

export interface ChatItemSlotClassNames {
Expand All @@ -22,6 +24,12 @@ export interface ChatItemSlotClassNames {
}

export interface ChatItemProps extends UIComponentProps, ChildrenComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility

/** Controls item's relation to other chat items. */
attached?: boolean | 'top' | 'bottom'

Expand Down Expand Up @@ -53,12 +61,14 @@ class ChatItem extends UIComponent<ReactProps<ChatItemProps>, any> {
}

static defaultProps = {
accessibility: defaultBehavior,
as: 'li',
contentPosition: 'start',
attached: false,
}

renderComponent({
accessibility,
ElementType,
classes,
unhandledProps,
Expand All @@ -69,6 +79,7 @@ class ChatItem extends UIComponent<ReactProps<ChatItemProps>, any> {
return (
<ElementType
{...rtlTextContainer.getAttributes({ forElements: [children] })}
{...accessibility.attributes.root}
{...unhandledProps}
className={classes.root}
>
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class ChatMessage extends UIComponent<ReactProps<ChatMessageProps>, ChatMessageS

static propTypes = {
...commonPropTypes.createCommon({ content: 'shorthand' }),
accessibility: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
actionMenu: customPropTypes.itemShorthand,
author: customPropTypes.itemShorthand,
badge: customPropTypes.itemShorthand,
Expand Down
1 change: 0 additions & 1 deletion packages/react/src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ class Dialog extends AutoControlledComponent<ReactProps<DialogProps>, DialogStat
content: true,
}),
actions: customPropTypes.itemShorthand,
accessibility: PropTypes.func,
cancelButton: customPropTypes.itemShorthand,
confirmButton: customPropTypes.itemShorthand,
defaultOpen: PropTypes.bool,
Expand Down
12 changes: 11 additions & 1 deletion packages/react/src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ import {
commonPropTypes,
rtlTextContainer,
} from '../../lib'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import { ReactProps } from '../../types'

export interface DividerProps
extends UIComponentProps,
ChildrenComponentProps,
ColorComponentProps,
ContentComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility

/** A divider can be fitted, without any space above or below it. */
fitted?: boolean

Expand Down Expand Up @@ -47,15 +55,17 @@ class Divider extends UIComponent<ReactProps<DividerProps>, any> {
}

static defaultProps = {
accessibility: defaultBehavior,
size: 0,
}

renderComponent({ ElementType, classes, unhandledProps }) {
renderComponent({ accessibility, ElementType, classes, unhandledProps }) {
const { children, content } = this.props

return (
<ElementType
{...rtlTextContainer.getAttributes({ forElements: [children, content] })}
{...accessibility.attributes.root}
{...unhandledProps}
className={classes.root}
>
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Dropdown extends AutoControlledComponent<Extendable<DropdownProps>, Dropdo

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure which component should not have the accessibility property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's not implemented yet #875

children: false,
content: false,
}),
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Dropdown/DropdownItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class DropdownItem extends UIComponent<ReactProps<DropdownItemProps>, any> {

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
children: false,
content: false,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class DropdownSearchInput extends UIComponent<ReactProps<DropdownSearchInputProp

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
children: false,
content: false,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class DropdownSelectedItem extends UIComponent<ReactProps<DropdownSelectedItemPr

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
children: false,
}),
active: PropTypes.bool,
Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Flex/Flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Flex extends UIComponent<ReactProps<FlexProps>> {

public static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
content: false,
}),

Expand Down
1 change: 1 addition & 0 deletions packages/react/src/components/Flex/FlexItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class FlexItem extends UIComponent<Extendable<FlexItemProps>> {

static propTypes = {
...commonPropTypes.createCommon({
accessibility: false,
content: false,
}),
align: PropTypes.oneOf(['auto', 'start', 'end', 'center', 'baseline', 'stretch']),
Expand Down
12 changes: 11 additions & 1 deletion packages/react/src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ import {
commonPropTypes,
rtlTextContainer,
} from '../../lib'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import { ComponentEventHandler, ReactProps, ShorthandValue } from '../../types'
import FormField from './FormField'

export interface FormProps extends UIComponentProps, ChildrenComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility

/** The HTML form action. */
action?: string

Expand Down Expand Up @@ -51,19 +59,21 @@ class Form extends UIComponent<ReactProps<FormProps>, any> {
}

public static defaultProps = {
accessibility: defaultBehavior,
as: 'form',
}

public static Field = FormField

public renderComponent({ ElementType, classes, unhandledProps }): React.ReactNode {
public renderComponent({ accessibility, ElementType, classes, unhandledProps }): React.ReactNode {
const { action, children } = this.props
return (
<ElementType
className={classes.root}
action={action}
onSubmit={this.handleSubmit}
{...rtlTextContainer.getAttributes({ forElements: [children] })}
{...accessibility.attributes.root}
{...unhandledProps}
>
{childrenExist(children) ? children : this.renderFields()}
Expand Down
11 changes: 10 additions & 1 deletion packages/react/src/components/Form/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import {
ChildrenComponentProps,
commonPropTypes,
} from '../../lib'
import { Accessibility } from '../../lib/accessibility/types'
import { defaultBehavior } from '../../lib/accessibility'
import { ReactProps, ShorthandValue } from '../../types'
import Text from '../Text/Text'
import Input from '../Input/Input'
import Box from '../Box/Box'

export interface FormFieldProps extends UIComponentProps, ChildrenComponentProps {
/**
* Accessibility behavior if overridden by the user.
* @default defaultBehavior
*/
accessibility?: Accessibility

/** A control for the form field. */
control?: ShorthandValue

Expand Down Expand Up @@ -66,6 +74,7 @@ class FormField extends UIComponent<ReactProps<FormFieldProps>, any> {
}

public static defaultProps = {
accessibility: defaultBehavior,
as: 'div',
control: { as: Input },
}
Expand Down Expand Up @@ -108,7 +117,7 @@ class FormField extends UIComponent<ReactProps<FormFieldProps>, any> {
)

return (
<ElementType className={classes.root} {...unhandledProps}>
<ElementType className={classes.root} {...accessibility.attributes.root} {...unhandledProps}>
{childrenExist(children) ? children : content}
</ElementType>
)
Expand Down
3 changes: 2 additions & 1 deletion packages/react/src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
...commonPropTypes.createCommon({
content: false,
}),
accessibility: PropTypes.func,
columns: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
content: customPropTypes.every([
customPropTypes.disallow(['children']),
Expand All @@ -66,6 +65,7 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
}

public renderComponent({
accessibility,
ElementType,
classes,
unhandledProps,
Expand All @@ -76,6 +76,7 @@ class Grid extends UIComponent<ReactProps<GridProps>, any> {
<ElementType
className={classes.root}
{...rtlTextContainer.getAttributes({ forElements: [children, content] })}
{...accessibility.attributes.root}
{...unhandledProps}
>
{childrenExist(children) ? children : content}
Expand Down
Loading