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 = [
8
8
{
9
9
label : '福建' ,
10
10
value : 'fj' ,
11
+ "aria-label" : '福建' ,
12
+ "aria-labelledby" : 'fj' ,
13
+ "data-type" : 'fj' ,
11
14
children : [
12
15
{
13
16
label : '福州' ,
Original file line number Diff line number Diff line change 1
1
import cls from 'classnames' ;
2
2
import * as React from 'react' ;
3
+ import pickAttrs from 'rc-util/lib/pickAttrs' ;
3
4
import type { DefaultOptionType , SingleValueType } from '../Cascader' ;
4
5
import CascaderContext from '../context' ;
5
6
import { SEARCH_MARK } from '../hooks/useSearchOptions' ;
@@ -139,6 +140,10 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
139
140
fullPathKey,
140
141
disableCheckbox,
141
142
} ) => {
143
+ const ariaProps = pickAttrs ( option , {
144
+ aria : true ,
145
+ data : true
146
+ } ) ;
142
147
// >>>>> Open
143
148
const triggerOpenPath = ( ) => {
144
149
if ( isOptionDisabled ( disabled ) ) {
@@ -170,6 +175,7 @@ export default function Column<OptionType extends DefaultOptionType = DefaultOpt
170
175
return (
171
176
< li
172
177
key = { fullPathKey }
178
+ { ...ariaProps }
173
179
className = { cls ( menuItemPrefixCls , classNames ?. popup ?. listItem , {
174
180
[ `${ menuItemPrefixCls } -expand` ] : ! isMergedLeaf ,
175
181
[ `${ menuItemPrefixCls } -active` ] :
Original file line number Diff line number Diff line change @@ -1154,4 +1154,39 @@ describe('Cascader.Basic', () => {
1154
1154
const { container } = render ( < Cascader ref = { cascaderRef } /> ) ;
1155
1155
expect ( cascaderRef . current ?. nativeElement ) . toEqual ( container . querySelector ( '.rc-cascader' ) ) ;
1156
1156
} ) ;
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
+ } ) ;
1157
1192
} ) ;
You can’t perform that action at this time.
0 commit comments