Skip to content

Commit f04fc2d

Browse files
committed
fix: avoid redundant segmented group tab stop
1 parent 8cbec0b commit f04fc2d

3 files changed

Lines changed: 10 additions & 20 deletions

File tree

src/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ const Segmented = React.forwardRef<HTMLDivElement, SegmentedProps>(
308308
<div
309309
role="radiogroup"
310310
aria-label="segmented control"
311-
tabIndex={disabled ? undefined : 0}
312311
aria-orientation={vertical ? 'vertical' : 'horizontal'}
313312
style={style}
314313
{...divProps}

tests/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exports[`rc-segmented render empty segmented 1`] = `
66
aria-orientation="horizontal"
77
class="rc-segmented"
88
role="radiogroup"
9-
tabindex="0"
109
>
1110
<div
1211
class="rc-segmented-group"
@@ -20,7 +19,6 @@ exports[`rc-segmented render label with ReactNode 1`] = `
2019
aria-orientation="horizontal"
2120
class="rc-segmented"
2221
role="radiogroup"
23-
tabindex="0"
2422
>
2523
<div
2624
class="rc-segmented-group"
@@ -82,7 +80,6 @@ exports[`rc-segmented render segmented ok 1`] = `
8280
aria-orientation="horizontal"
8381
class="rc-segmented"
8482
role="radiogroup"
85-
tabindex="0"
8683
>
8784
<div
8885
class="rc-segmented-group"
@@ -140,7 +137,6 @@ exports[`rc-segmented render segmented with CSSMotion basic 1`] = `
140137
aria-orientation="horizontal"
141138
class="rc-segmented"
142139
role="radiogroup"
143-
tabindex="0"
144140
>
145141
<div
146142
class="rc-segmented-group"
@@ -198,7 +194,6 @@ exports[`rc-segmented render segmented with options 1`] = `
198194
aria-orientation="horizontal"
199195
class="rc-segmented"
200196
role="radiogroup"
201-
tabindex="0"
202197
>
203198
<div
204199
class="rc-segmented-group"
@@ -308,7 +303,6 @@ exports[`rc-segmented render segmented with options: 1 1`] = `
308303
aria-orientation="horizontal"
309304
class="rc-segmented"
310305
role="radiogroup"
311-
tabindex="0"
312306
>
313307
<div
314308
class="rc-segmented-group"
@@ -394,7 +388,6 @@ exports[`rc-segmented render segmented with options: 2 1`] = `
394388
aria-orientation="horizontal"
395389
class="rc-segmented"
396390
role="radiogroup"
397-
tabindex="0"
398391
>
399392
<div
400393
class="rc-segmented-group"
@@ -452,7 +445,6 @@ exports[`rc-segmented render segmented with options: disabled 1`] = `
452445
aria-orientation="horizontal"
453446
class="rc-segmented"
454447
role="radiogroup"
455-
tabindex="0"
456448
>
457449
<div
458450
class="rc-segmented-group"
@@ -511,7 +503,6 @@ exports[`rc-segmented render segmented with title 1`] = `
511503
aria-orientation="horizontal"
512504
class="rc-segmented"
513505
role="radiogroup"
514-
tabindex="0"
515506
>
516507
<div
517508
class="rc-segmented-group"
@@ -658,7 +649,6 @@ exports[`rc-segmented should render vertical segmented 1`] = `
658649
aria-orientation="vertical"
659650
class="rc-segmented rc-segmented-vertical"
660651
role="radiogroup"
661-
tabindex="0"
662652
>
663653
<div
664654
class="rc-segmented-group"
@@ -716,7 +706,6 @@ exports[`rc-segmented should render vertical segmented and handle thumb animatio
716706
aria-orientation="vertical"
717707
class="rc-segmented rc-segmented-vertical"
718708
role="radiogroup"
719-
tabindex="0"
720709
>
721710
<div
722711
class="rc-segmented-group"

tests/index.test.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,22 +687,26 @@ describe('Segmented keyboard navigation', () => {
687687
const firstInput = inputs[0];
688688

689689
await user.tab();
690-
// segmented container should be focused
691-
expect(segmentedContainer).toHaveFocus();
692-
await user.tab();
693-
// first segmented item should be focused
690+
// The radio group should not add an empty stop before its native radios.
691+
expect(segmentedContainer).not.toHaveAttribute('tabindex');
694692
expect(firstInput).toHaveFocus();
695693
});
696694

695+
it('should honor an explicit group tabIndex', () => {
696+
const { getByRole } = render(
697+
<Segmented options={['Daily', 'Weekly', 'Monthly']} tabIndex={0} />,
698+
);
699+
700+
expect(getByRole('radiogroup')).toHaveAttribute('tabindex', '0');
701+
});
702+
697703
it('should handle circular navigation with arrow keys', async () => {
698704
const user = userEvent.setup();
699705
const onChange = jest.fn();
700706
render(
701707
<Segmented options={['iOS', 'Android', 'Web']} onChange={onChange} />,
702708
);
703709

704-
// focus on segmented
705-
await user.tab();
706710
// focus on first item
707711
await user.tab();
708712

@@ -751,7 +755,6 @@ describe('Segmented keyboard navigation', () => {
751755
/>,
752756
);
753757

754-
await user.tab();
755758
await user.tab();
756759

757760
await user.keyboard('{ArrowRight}');
@@ -777,7 +780,6 @@ describe('Segmented keyboard navigation', () => {
777780
/>,
778781
);
779782

780-
await user.tab();
781783
await user.tab();
782784
await user.keyboard('{ArrowRight}');
783785

0 commit comments

Comments
 (0)