@@ -132,4 +132,87 @@ describe('Select.Accessibility', () => {
132
132
} ) ;
133
133
expectOpen ( container ) ;
134
134
} ) ;
135
+
136
+ // https://github.com/ant-design/ant-design/issues/53713
137
+ describe ( 'Select ARIA attributes' , ( ) => {
138
+ it ( 'should have correct aria and role attributes in virtual true' , ( ) => {
139
+ render (
140
+ < Select
141
+ id = "virtual-select"
142
+ open = { true }
143
+ options = { [
144
+ {
145
+ value : '123' ,
146
+ } ,
147
+ {
148
+ value : '1234' ,
149
+ } ,
150
+ {
151
+ value : '12345' ,
152
+ } ,
153
+ ] }
154
+ /> ,
155
+ ) ;
156
+
157
+ const dropdown = document . querySelector ( '#virtual-select_list' ) ;
158
+ expect ( dropdown ) . toHaveAttribute ( 'role' , 'listbox' ) ;
159
+
160
+ const options = dropdown . querySelectorAll ( 'div' ) ;
161
+ options . forEach ( ( option ) => {
162
+ // 每个 option 应该有 role="option"
163
+ expect ( option ) . toHaveAttribute ( 'role' , 'option' ) ;
164
+
165
+ // 如果有 aria-selected,确保值是 true/false
166
+ const ariaSelected = option . getAttribute ( 'aria-selected' ) ;
167
+ if ( ariaSelected !== null ) {
168
+ expect ( [ 'true' , 'false' ] ) . toContain ( ariaSelected ) ;
169
+ }
170
+ } ) ;
171
+
172
+ const rcVirtual = document . querySelector ( '.rc-virtual-list-holder-inner' ) ;
173
+ expect ( rcVirtual ) . not . toHaveAttribute ( 'role' ) ;
174
+ const rcOptionItem = rcVirtual . querySelectorAll ( '.rc-select-item-option' ) ;
175
+
176
+ rcOptionItem . forEach ( ( option ) => {
177
+ expect ( option ) . not . toHaveAttribute ( 'role' ) ;
178
+ expect ( option ) . not . toHaveAttribute ( 'aria-selected' ) ;
179
+ } ) ;
180
+ } ) ;
181
+
182
+ it ( 'should have correct aria and role attributes in virtual false' , ( ) => {
183
+ render (
184
+ < Select
185
+ id = "virtual-select"
186
+ open
187
+ virtual = { false }
188
+ options = { [
189
+ {
190
+ value : '123' ,
191
+ } ,
192
+ {
193
+ value : '1234' ,
194
+ } ,
195
+ {
196
+ value : '12345' ,
197
+ } ,
198
+ ] }
199
+ /> ,
200
+ ) ;
201
+
202
+ const dropdown = document . querySelector ( '#virtual-select_list' ) ;
203
+ expect ( dropdown ) . toHaveAttribute ( 'role' , 'listbox' ) ;
204
+
205
+ const options = dropdown . querySelectorAll ( '.rc-select-item-option' ) ;
206
+ options . forEach ( ( option ) => {
207
+ // 每个 option 应该有 role="option"
208
+ expect ( option ) . toHaveAttribute ( 'role' , 'option' ) ;
209
+
210
+ // 如果有 aria-selected,确保值是 true/false
211
+ const ariaSelected = option . getAttribute ( 'aria-selected' ) ;
212
+ if ( ariaSelected !== null ) {
213
+ expect ( [ 'true' , 'false' ] ) . toContain ( ariaSelected ) ;
214
+ }
215
+ } ) ;
216
+ } ) ;
217
+ } ) ;
135
218
} ) ;
0 commit comments