Skip to content

Commit accc883

Browse files
authored
auto aria-label (#491)
1 parent e5f5d02 commit accc883

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

src/OptionList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,12 @@ const OptionList: React.RefForwardingComponent<
235235
if (!item) return null;
236236

237237
const itemData = (item.data || {}) as OptionData;
238-
const { value } = itemData;
238+
const { value, label, children } = itemData;
239239
const attrs = pickAttrs(itemData, true);
240+
const mergedLabel = childrenAsData ? children : label;
240241
return item ? (
241242
<div
243+
aria-label={typeof mergedLabel === 'string' ? mergedLabel : null}
242244
{...attrs}
243245
key={index}
244246
role="option"

tests/OptionList.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ describe('OptionList', () => {
141141
it('Data attributes should be set correct', () => {
142142
const wrapper = mount(
143143
generateList({
144-
options: [{ value: '1' }, { value: '2', 'data-num': '123' }],
144+
options: [{ value: '1', label: 'my-label' }, { value: '2', 'data-num': '123' }],
145145
}),
146146
);
147147

tests/__snapshots__/Select.test.tsx.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ exports[`Select.Basic does not filter when filterOption value is false 1`] = `
3939
style="height:0;width:0;overflow:hidden"
4040
>
4141
<div
42+
aria-label="1"
4243
aria-selected="false"
4344
id="undefined_list_0"
4445
role="option"
4546
>
4647
1
4748
</div>
4849
<div
50+
aria-label="2"
4951
aria-selected="false"
5052
id="undefined_list_1"
5153
role="option"
@@ -490,6 +492,7 @@ exports[`Select.Basic render renders dropdown correctly 1`] = `
490492
jack
491493
</div>
492494
<div
495+
aria-label="lucy"
493496
aria-selected="false"
494497
id="undefined_list_2"
495498
role="option"
@@ -712,13 +715,15 @@ exports[`Select.Basic should contain falsy children 1`] = `
712715
style="height:0;width:0;overflow:hidden"
713716
>
714717
<div
718+
aria-label="1"
715719
aria-selected="true"
716720
id="undefined_list_0"
717721
role="option"
718722
>
719723
1
720724
</div>
721725
<div
726+
aria-label="2"
722727
aria-selected="false"
723728
id="undefined_list_1"
724729
role="option"
@@ -845,13 +850,15 @@ exports[`Select.Basic should render custom dropdown correctly 1`] = `
845850
style="height: 0px; width: 0px; overflow: hidden;"
846851
>
847852
<div
853+
aria-label="1"
848854
aria-selected="false"
849855
id="rc_select_TEST_OR_SSR_list_0"
850856
role="option"
851857
>
852858
1
853859
</div>
854860
<div
861+
aria-label="2"
855862
aria-selected="false"
856863
id="rc_select_TEST_OR_SSR_list_1"
857864
role="option"

tests/__snapshots__/Tags.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
9292
role="option"
9393
/>
9494
<div
95+
aria-label="Jack"
9596
aria-selected="true"
9697
id="rc_select_TEST_OR_SSR_list_1"
9798
role="option"

0 commit comments

Comments
 (0)