Skip to content

Commit 156b142

Browse files
kiner-tangtangwenhui1
andauthored
feat: support aria-* and data-* (#592)
Co-authored-by: tangwenhui1 <tangwenhui1@yy.com>
1 parent f8cb450 commit 156b142

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

examples/simple.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const addressOptions = [
88
{
99
label: '福建',
1010
value: 'fj',
11+
"aria-label": '福建',
12+
"aria-labelledby": 'fj',
13+
"data-type": 'fj',
1114
children: [
1215
{
1316
label: '福州',

src/OptionList/Column.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cls from 'classnames';
22
import * as React from 'react';
3+
import pickAttrs from 'rc-util/lib/pickAttrs';
34
import type { DefaultOptionType, SingleValueType } from '../Cascader';
45
import CascaderContext from '../context';
56
import { SEARCH_MARK } from '../hooks/useSearchOptions';
@@ -139,6 +140,10 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
139140
fullPathKey,
140141
disableCheckbox,
141142
}) => {
143+
const ariaProps = pickAttrs(option, {
144+
aria: true,
145+
data: true
146+
});
142147
// >>>>> Open
143148
const triggerOpenPath = () => {
144149
if (isOptionDisabled(disabled)) {
@@ -170,6 +175,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
170175
return (
171176
<li
172177
key={fullPathKey}
178+
{...ariaProps}
173179
className={cls(menuItemPrefixCls, classNames?.popup?.listItem, {
174180
[`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
175181
[`${menuItemPrefixCls}-active`]:

tests/index.spec.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,4 +1154,39 @@ describe('Cascader.Basic', () => {
11541154
const { container } = render(<Cascader ref={cascaderRef} />);
11551155
expect(cascaderRef.current?.nativeElement).toEqual(container.querySelector('.rc-cascader'));
11561156
});
1157+
1158+
it('support aria-* and data-*', () => {
1159+
const options: CascaderProps["options"] = [
1160+
{
1161+
label: '福建',
1162+
value: 'fj',
1163+
"aria-label": '福建',
1164+
"aria-labelledby": 'fj',
1165+
"data-type": 'fj',
1166+
children: [
1167+
{
1168+
label: '福州',
1169+
value: 'fuzhou',
1170+
children: [
1171+
{
1172+
label: '马尾',
1173+
value: 'mawei',
1174+
},
1175+
],
1176+
},
1177+
{
1178+
label: '泉州',
1179+
value: 'quanzhou',
1180+
},
1181+
],
1182+
},
1183+
];
1184+
const { container } = render(<Cascader options={options} />);
1185+
const item = container.querySelector('.rc-cascader-menu-item');
1186+
if (item) {
1187+
expect(item.getAttribute('aria-label')).toBe('福建');
1188+
expect(item.getAttribute('aria-labelledby')).toBe('fj');
1189+
expect(item.getAttribute('data-type')).toBe('fj');
1190+
}
1191+
});
11571192
});

0 commit comments

Comments
 (0)