Skip to content

Commit 7970717

Browse files
committed
chore: Select option pass aria-info to a11y util
fix ant-design/ant-design#24331
1 parent 8e06378 commit 7970717

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"classnames": "2.x",
4747
"rc-animate": "^3.0.0",
4848
"rc-trigger": "^4.0.0",
49-
"rc-util": "^4.20.0",
49+
"rc-util": "^4.20.6",
5050
"rc-virtual-list": "^1.1.2",
5151
"warning": "^4.0.3"
5252
},
@@ -64,6 +64,6 @@
6464
"jsonp": "^0.2.1",
6565
"np": "^6.0.0",
6666
"rc-dialog": "^7.5.5",
67-
"typescript": "^3.5.2"
67+
"typescript": "^3.9.3"
6868
}
6969
}

src/OptionList.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import KeyCode from 'rc-util/lib/KeyCode';
3+
import pickAttrs from 'rc-util/lib/pickAttrs';
34
import useMemo from 'rc-util/lib/hooks/useMemo';
45
import classNames from 'classnames';
56
import List from 'rc-virtual-list';
@@ -231,9 +232,19 @@ const OptionList: React.RefForwardingComponent<
231232

232233
function renderItem(index: number) {
233234
const item = memoFlattenOptions[index];
234-
const value = item && (item.data as OptionData).value;
235+
if (!item) return null;
236+
237+
const itemData = (item.data || {}) as OptionData;
238+
const { value } = itemData;
239+
const attrs = pickAttrs(itemData, true);
235240
return item ? (
236-
<div key={index} role="option" id={`${id}_list_${index}`} aria-selected={values.has(value)}>
241+
<div
242+
{...attrs}
243+
key={index}
244+
role="option"
245+
id={`${id}_list_${index}`}
246+
aria-selected={values.has(value)}
247+
>
237248
{value}
238249
</div>
239250
) : null;

tests/OptionList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('OptionList', () => {
4444
options: [
4545
{
4646
key: 'group1',
47-
options: [{ value: '1' }],
47+
options: [{ value: '1', 'aria-label': 'value-1' }],
4848
},
4949
{
5050
key: 'group2',

tests/__snapshots__/OptionList.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ exports[`OptionList renders correctly 1`] = `
1313
role="option"
1414
/>
1515
<div
16+
aria-label="value-1"
1617
aria-selected="true"
1718
id="undefined_list_1"
1819
role="option"
@@ -39,6 +40,7 @@ exports[`OptionList renders correctly 1`] = `
3940
group1
4041
</div>
4142
<div
43+
aria-label="value-1"
4244
aria-selected="true"
4345
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active rc-select-item-option-selected"
4446
>

0 commit comments

Comments
 (0)