Skip to content
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

Accessibility/badge #777

Merged
merged 4 commits into from
May 4, 2018
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `0.0.46`.
**Bug fixes**

- Added aria labeling requirements for `EuiBadge` , as well as a generic prop_type function `requiresAriaLabel` in `utils` to check for it. ([#777](https://github.com/elastic/eui/pull/777))

## [`0.0.46`](https://github.com/elastic/eui/tree/v0.0.46)

Expand Down
2 changes: 2 additions & 0 deletions src-docs/src/views/badge/badge_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default () => (
<EuiBadge
color="#333"
onClick={() => window.alert('Badge clicked')}
onClickAriaLabel="Example of onclick event for the button"
>
onClick on badge itself
</EuiBadge>
Expand All @@ -18,6 +19,7 @@ export default () => (
iconSide="right"
color="#333"
iconOnClick={() => window.alert('Icon inside badge clicked')}
iconOnClickAriaLabel="Example of onclick event for icon within the button"
>
onClick on icon within badge
</EuiBadge>
Expand Down
25 changes: 24 additions & 1 deletion src/components/badge/badge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { EuiPropTypes } from '../../utils';

import { isColorDark, hexToRgb } from '../../services/color';
import { EuiKeyboardAccessible } from '../accessibility';
Expand Down Expand Up @@ -37,6 +38,8 @@ export const EuiBadge = ({
className,
onClick,
iconOnClick,
onClickAriaLabel,
iconOnClickAriaLabel,
closeButtonProps,
...rest
}) => {
Expand Down Expand Up @@ -71,7 +74,14 @@ export const EuiBadge = ({
if (iconOnClick) {
optionalIcon = (
<EuiKeyboardAccessible>
<EuiIcon onClick={iconOnClick} type={iconType} size="s" className="euiBadge__icon" {...closeButtonProps} />
<EuiIcon
onClick={iconOnClick}
type={iconType}
size="s"
className="euiBadge__icon"
aria-label={iconOnClickAriaLabel}
{...closeButtonProps}
/>
</EuiKeyboardAccessible>
);

Expand All @@ -88,6 +98,7 @@ export const EuiBadge = ({
className={classes}
style={optionalCustomStyles}
onClick={onClick}
aria-label={onClickAriaLabel}
{...rest}
>
<span className="euiBadge__content">
Expand Down Expand Up @@ -116,6 +127,8 @@ export const EuiBadge = ({
}
};



function checkValidColor(props, propName, componentName) {
const validHex = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(props.color);
if (props.color && !validHex && !COLORS.includes(props.color)) {
Expand Down Expand Up @@ -144,11 +157,21 @@ EuiBadge.propTypes = {
*/
iconOnClick: PropTypes.func,

/**
* Aria label applied to the iconOnClick button
*/
iconOnClickAriaLabel: EuiPropTypes.requiresAriaLabel('iconOnClick', 'iconOnClickAriaLabel'),

/**
* Will apply an onclick to the badge itself
*/
onClick: PropTypes.func,

/**
* Aria label applied to the iconOnClick button
*/
iconOnClickAriaLabel: EuiPropTypes.requiresAriaLabel('onClick', 'onClickAriaLabel'),

/**
* Accepts either our palette colors (primary, secondary ..etc) or a hex value `#FFFFFF`, `#000`.
*/
Expand Down
1 change: 1 addition & 0 deletions src/components/combo_box/combo_box_input/combo_box_pill.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class EuiComboBoxPill extends Component {
className={classes}
title={children}
iconOnClick={this.onCloseButtonClick}
iconOnClickAriaLabel={`Remove ${children} from selection in this group`}
iconType="cross"
iconSide="right"
color={color}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/prop_types/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { is } from './is';
import { requiresAriaLabel } from './requires_aria_label';

export const EuiPropTypes = {
is
is,
requiresAriaLabel,
};
15 changes: 15 additions & 0 deletions src/utils/prop_types/requires_aria_label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const requiresAriaLabel = (action, label) => {

const validator = (props, propName, componentName) => {
if (props[action] && !props[label]) {
return new Error(
`Please provide an aria label to compliment your ${action} ` +
`prop in ${componentName}`
);
}

return null;
};

return validator;
};