From 793e8da1adce2f554e5351d4bfeccf866e8742ea Mon Sep 17 00:00:00 2001 From: tangwenhui1 Date: Sat, 17 May 2025 11:43:47 +0800 Subject: [PATCH] feat: support data-* & aria-* --- examples/simple.tsx | 3 +++ src/OptionList/Column.tsx | 6 ++++++ tests/index.spec.tsx | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/examples/simple.tsx b/examples/simple.tsx index ebad6c64..583cecf1 100644 --- a/examples/simple.tsx +++ b/examples/simple.tsx @@ -8,6 +8,9 @@ const addressOptions = [ { label: '福建', value: 'fj', + "aria-label": '福建', + "aria-labelledby": 'fj', + "data-type": 'fj', children: [ { label: '福州', diff --git a/src/OptionList/Column.tsx b/src/OptionList/Column.tsx index c46cc457..5a62375e 100644 --- a/src/OptionList/Column.tsx +++ b/src/OptionList/Column.tsx @@ -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'; @@ -117,6 +118,10 @@ export default function Column { + const ariaProps = pickAttrs(option, { + aria: true, + data: true + }); // >>>>> Open const triggerOpenPath = () => { if (isOptionDisabled(disabled)) { @@ -148,6 +153,7 @@ export default function Column { const { container } = render(); 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(); + 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'); + } + }); });