@@ -132,4 +132,82 @@ 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 hiddenOptions = dropdown . querySelectorAll ( 'div[style*="height: 0"] div[role="option"]' ) ;
161
+ expect ( hiddenOptions . length ) . toBeGreaterThan ( 0 ) ;
162
+ hiddenOptions . forEach ( ( option ) => {
163
+ expect ( option ) . toHaveAttribute ( 'role' , 'option' ) ;
164
+ const ariaSelected = option . getAttribute ( 'aria-selected' ) ;
165
+ if ( ariaSelected !== null ) {
166
+ expect ( [ 'true' , 'false' ] ) . toContain ( ariaSelected ) ;
167
+ }
168
+ } ) ;
169
+
170
+ const rcVirtual = document . querySelector ( '.rc-virtual-list-holder-inner' ) ;
171
+ expect ( rcVirtual ) . not . toHaveAttribute ( 'role' ) ;
172
+ const rcOptionItem = rcVirtual . querySelectorAll ( '.rc-select-item-option' ) ;
173
+
174
+ rcOptionItem . forEach ( ( option ) => {
175
+ expect ( option ) . not . toHaveAttribute ( 'role' ) ;
176
+ expect ( option ) . not . toHaveAttribute ( 'aria-selected' ) ;
177
+ } ) ;
178
+ } ) ;
179
+
180
+ it ( 'should have correct aria and role attributes in virtual false' , ( ) => {
181
+ render (
182
+ < Select
183
+ id = "virtual-select"
184
+ open
185
+ virtual = { false }
186
+ options = { [
187
+ {
188
+ value : '123' ,
189
+ } ,
190
+ {
191
+ value : '1234' ,
192
+ } ,
193
+ {
194
+ value : '12345' ,
195
+ } ,
196
+ ] }
197
+ /> ,
198
+ ) ;
199
+
200
+ const dropdown = document . querySelector ( '#virtual-select_list' ) ;
201
+ expect ( dropdown ) . toHaveAttribute ( 'role' , 'listbox' ) ;
202
+
203
+ const options = dropdown . querySelectorAll ( '.rc-select-item-option' ) ;
204
+ options . forEach ( ( option ) => {
205
+ expect ( option ) . toHaveAttribute ( 'role' , 'option' ) ;
206
+ const ariaSelected = option . getAttribute ( 'aria-selected' ) ;
207
+ if ( ariaSelected !== null ) {
208
+ expect ( [ 'true' , 'false' ] ) . toContain ( ariaSelected ) ;
209
+ }
210
+ } ) ;
211
+ } ) ;
212
+ } ) ;
135
213
} ) ;
0 commit comments