Skip to content

Commit

Permalink
test(Rating): add a11y support for aria-label
Browse files Browse the repository at this point in the history
  • Loading branch information
jinchanz committed Mar 7, 2019
1 parent a038186 commit ce5b103
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/locale/en-us.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ export default {
Tag: {
delete: 'Delete',
},
Rating: {
description: 'Rating Options',
},
};
3 changes: 3 additions & 0 deletions src/locale/ja-jp.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ export default {
Tag: {
delete: 'デリート',
},
Rating: {
description: '評価オプション',
},
};
3 changes: 3 additions & 0 deletions src/locale/zh-cn.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ export default {
Tag: {
delete: '删除',
},
Rating: {
description: '评分选项',
},
};
3 changes: 3 additions & 0 deletions src/locale/zh-tw.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ export default {
Tag: {
delete: '删除',
},
Rating: {
description: '評分選項',
},
};
23 changes: 10 additions & 13 deletions src/rating/rating.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import classNames from 'classnames';
import Icon from '../icon';
import { func, KEYCODE, obj } from '../util';
import zhCN from '../locale/zh-cn';

const { noop, bindCtx } = func;
const { ENTER, LEFT, UP, RIGHT, DOWN } = KEYCODE;
Expand Down Expand Up @@ -68,6 +69,10 @@ export default class Rating extends Component {
className: PropTypes.string,
id: PropTypes.string,
rtl: PropTypes.bool,
/**
* 自定义国际化文案对象
*/
locale: PropTypes.object,
};

static defaultProps = {
Expand All @@ -82,6 +87,7 @@ export default class Rating extends Component {
iconType: 'favorites-filling',
onChange: noop,
onHoverChange: noop,
locale: zhCN.Rating,
};

static currentValue(min, max, hoverValue, stateValue) {
Expand Down Expand Up @@ -306,6 +312,7 @@ export default class Rating extends Component {
disabled,
readAs,
rtl,
locale,
} = this.props;
const others = obj.pickOthers(Rating.propTypes, this.props);
const { hoverValue, clicked } = this.state;
Expand Down Expand Up @@ -419,6 +426,8 @@ export default class Rating extends Component {
className={ratingCls}
onKeyDown={this.onKeyDown}
tabIndex="0"
role="group"
aria-label={locale.description}
>
<div className={baseCls} {...finalProps}>
<div
Expand All @@ -431,19 +440,7 @@ export default class Rating extends Component {
className={`${prefix}rating-overlay`}
style={overlayStyle}
>
<form action="#">
{enableA11y ? (
<div
role="group"
aria-labelledby={id}
aria-label="Rating Options"
>
{overlay}
</div>
) : (
overlay
)}
</form>
<form action="#">{overlay}</form>
</div>
</div>
{showGrade ? (
Expand Down

0 comments on commit ce5b103

Please sign in to comment.