File tree Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Expand file tree Collapse file tree 3 files changed +44
-0
lines changed Original file line number Diff line number Diff 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 : '福州' ,
Original file line number Diff line number Diff line change 11import cls from 'classnames' ;
22import * as React from 'react' ;
3+ import pickAttrs from 'rc-util/lib/pickAttrs' ;
34import type { DefaultOptionType , SingleValueType } from '../Cascader' ;
45import CascaderContext from '../context' ;
56import { 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` ] :
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments