Skip to content
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
3 changes: 3 additions & 0 deletions examples/simple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const addressOptions = [
{
label: '福建',
value: 'fj',
"aria-label": '福建',
"aria-labelledby": 'fj',
"data-type": 'fj',
children: [
{
label: '福州',
Expand Down
6 changes: 6 additions & 0 deletions src/OptionList/Column.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cls from 'classnames';
import * as React from 'react';
import pickAttrs from 'rc-util/lib/pickAttrs';
import type { DefaultOptionType, SingleValueType } from '../Cascader';
import CascaderContext from '../context';
import { SEARCH_MARK } from '../hooks/useSearchOptions';
Expand Down Expand Up @@ -139,6 +140,10 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
fullPathKey,
disableCheckbox,
}) => {
const ariaProps = pickAttrs(option, {
aria: true,
data: true
});
// >>>>> Open
const triggerOpenPath = () => {
if (isOptionDisabled(disabled)) {
Expand Down Expand Up @@ -170,6 +175,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
return (
<li
key={fullPathKey}
{...ariaProps}
className={cls(menuItemPrefixCls, classNames?.popup?.listItem, {
[`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
[`${menuItemPrefixCls}-active`]:
Expand Down
35 changes: 35 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1154,4 +1154,39 @@ describe('Cascader.Basic', () => {
const { container } = render(<Cascader ref={cascaderRef} />);
expect(cascaderRef.current?.nativeElement).toEqual(container.querySelector('.rc-cascader'));
});

it('support aria-* and data-*', () => {
const options: CascaderProps["options"] = [
{
label: '福建',
value: 'fj',
"aria-label": '福建',
"aria-labelledby": 'fj',
"data-type": 'fj',
children: [
{
label: '福州',
value: 'fuzhou',
children: [
{
label: '马尾',
value: 'mawei',
},
],
},
{
label: '泉州',
value: 'quanzhou',
},
],
},
];
const { container } = render(<Cascader options={options} />);
const item = container.querySelector('.rc-cascader-menu-item');
if (item) {
expect(item.getAttribute('aria-label')).toBe('福建');
expect(item.getAttribute('aria-labelledby')).toBe('fj');
expect(item.getAttribute('data-type')).toBe('fj');
}
});
});
Loading