Skip to content
Open
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 numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
import classNames 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 DownExpand Up@@ -117,6 +118,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 DownExpand Up@@ -148,6 +153,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
return (
<li
key={fullPathKey}
{...ariaProps}
className={classNames(menuItemPrefixCls, {
[`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
[`${menuItemPrefixCls}-active`]:
Expand Down
34 changes: 34 additions & 0 deletions tests/index.spec.tsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -1162,4 +1162,38 @@ 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');
}
});
});