Skip to content

Commit f432162

Browse files
authored
[tabs] Change activateOnFocus to false (#3176)
1 parent 0def33c commit f432162

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

docs/reference/generated/tabs-list.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"props": {
55
"activateOnFocus": {
66
"type": "boolean",
7-
"default": "true",
7+
"default": "false",
88
"description": "Whether to automatically change the active tab on arrow key focus.\nOtherwise, tabs will be activated using Enter or Spacebar key press.",
99
"detailedType": "boolean | undefined"
1010
},

packages/react/src/tabs/list/TabsList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const TabsList = React.forwardRef(function TabsList(
2323
forwardedRef: React.ForwardedRef<HTMLDivElement>,
2424
) {
2525
const {
26-
activateOnFocus = true,
26+
activateOnFocus = false,
2727
className,
2828
loop = true,
2929
render,
@@ -202,7 +202,7 @@ export interface TabsListProps extends BaseUIComponentProps<'div', TabsList.Stat
202202
/**
203203
* Whether to automatically change the active tab on arrow key focus.
204204
* Otherwise, tabs will be activated using Enter or Spacebar key press.
205-
* @default true
205+
* @default false
206206
*/
207207
activateOnFocus?: boolean;
208208
/**

packages/react/src/tabs/root/TabsRoot.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ describe('<Tabs.Root />', () => {
174174
});
175175

176176
describe('prop: onValueChange', () => {
177-
it('should call onValueChange on pointerdown', async () => {
177+
it('when `activateOnFocus = true` should call onValueChange on pointerdown', async () => {
178178
const handleChange = spy();
179179
const handlePointerDown = spy();
180180
const { user } = await render(
181181
<Tabs.Root value={0} onValueChange={handleChange}>
182-
<Tabs.List>
182+
<Tabs.List activateOnFocus>
183183
<Tabs.Tab value={0} />
184184
<Tabs.Tab value={1} onPointerDown={handlePointerDown} />
185185
</Tabs.List>
@@ -241,12 +241,12 @@ describe('<Tabs.Root />', () => {
241241
expect(handleChange.callCount).to.equal(0);
242242
});
243243

244-
it('should call onValueChange if an unactive tab gets focused', async () => {
244+
it('when `activateOnFocus = true` should call onValueChange if an unactive tab gets focused', async () => {
245245
const handleChange = spy();
246246

247247
await render(
248248
<Tabs.Root value={0} onValueChange={handleChange}>
249-
<Tabs.List>
249+
<Tabs.List activateOnFocus>
250250
<Tabs.Tab value={0} />
251251
<Tabs.Tab value={1} />
252252
</Tabs.List>
@@ -491,7 +491,7 @@ describe('<Tabs.Root />', () => {
491491
orientation={orientation as Tabs.Root.Props['orientation']}
492492
value={0}
493493
>
494-
<Tabs.List onKeyDown={handleKeyDown}>
494+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
495495
<Tabs.Tab value={0} />
496496
<Tabs.Tab value={1} />
497497
<Tabs.Tab value={2} />
@@ -526,7 +526,7 @@ describe('<Tabs.Root />', () => {
526526
orientation={orientation as Tabs.Root.Props['orientation']}
527527
value={1}
528528
>
529-
<Tabs.List onKeyDown={handleKeyDown}>
529+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
530530
<Tabs.Tab value={0} />
531531
<Tabs.Tab value={1} />
532532
<Tabs.Tab value={2} />
@@ -701,7 +701,7 @@ describe('<Tabs.Root />', () => {
701701
orientation={orientation as Tabs.Root.Props['orientation']}
702702
value={2}
703703
>
704-
<Tabs.List onKeyDown={handleKeyDown}>
704+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
705705
<Tabs.Tab value={0} />
706706
<Tabs.Tab value={1} />
707707
<Tabs.Tab value={2} />
@@ -736,7 +736,7 @@ describe('<Tabs.Root />', () => {
736736
orientation={orientation as Tabs.Root.Props['orientation']}
737737
value={1}
738738
>
739-
<Tabs.List onKeyDown={handleKeyDown}>
739+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
740740
<Tabs.Tab value={0} />
741741
<Tabs.Tab value={1} />
742742
<Tabs.Tab value={2} />
@@ -878,7 +878,7 @@ describe('<Tabs.Root />', () => {
878878

879879
await render(
880880
<Tabs.Root onValueChange={handleChange} value={2}>
881-
<Tabs.List onKeyDown={handleKeyDown}>
881+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
882882
<Tabs.Tab value={0} />
883883
<Tabs.Tab value={1} />
884884
<Tabs.Tab value={2} />
@@ -967,7 +967,7 @@ describe('<Tabs.Root />', () => {
967967

968968
await render(
969969
<Tabs.Root onValueChange={handleChange} value={0}>
970-
<Tabs.List onKeyDown={handleKeyDown}>
970+
<Tabs.List onKeyDown={handleKeyDown} activateOnFocus>
971971
<Tabs.Tab value={0} />
972972
<Tabs.Tab value={1} />
973973
<Tabs.Tab value={2} />

packages/react/src/tabs/tab/TabsTab.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ export const TabsTab = React.forwardRef(function TabsTab(
140140
}
141141

142142
if (
143-
(activateOnFocus && !isPressingRef.current) || // keyboard or touch focus
144-
(isPressingRef.current && isMainButtonRef.current) // mouse focus
143+
activateOnFocus &&
144+
(!isPressingRef.current || // keyboard or touch focus
145+
(isPressingRef.current && isMainButtonRef.current)) // mouse focus
145146
) {
146147
onTabActivation(
147148
tabValue,

0 commit comments

Comments
 (0)