Skip to content

Commit c22a8c1

Browse files
authored
Don't assume <Tab /> components are available when setting the next index (#2642)
* only set the next index when tabs are available Currently we were assuming that the `tabs` were always there, but this * update changelog
1 parent 6f9de89 commit c22a8c1

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

packages/@headlessui-react/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Use correct value when resetting `<Listbox multiple>` and `<Combobox multiple>` ([#2626](https://github.com/tailwindlabs/headlessui/pull/2626))
1313
- Render `<MainTreeNode />` in `Popover.Group` component only ([#2634](https://github.com/tailwindlabs/headlessui/pull/2634))
1414
- Disable smooth scrolling when opening/closing `Dialog` components on iOS ([#2635](https://github.com/tailwindlabs/headlessui/pull/2635))
15+
- Don't assume `<Tab />` components are available when setting the next index ([#2642](https://github.com/tailwindlabs/headlessui/pull/2642))
1516

1617
## [1.7.16] - 2023-07-27
1718

packages/@headlessui-react/src/components/tabs/tabs.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ let reducers: {
114114
return nextState
115115
}
116116

117+
let nextSelectedIndex = match(direction, {
118+
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
119+
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
120+
})
121+
117122
return {
118123
...nextState,
119-
selectedIndex: match(direction, {
120-
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
121-
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
122-
}),
124+
selectedIndex: nextSelectedIndex === -1 ? state.selectedIndex : nextSelectedIndex,
123125
}
124126
}
125127

packages/@headlessui-vue/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Use correct value when resetting `<Listbox multiple>` and `<Combobox multiple>` ([#2626](https://github.com/tailwindlabs/headlessui/pull/2626))
1414
- Render `<MainTreeNode />` in `PopoverGroup` component only ([#2634](https://github.com/tailwindlabs/headlessui/pull/2634))
1515
- Disable smooth scrolling when opening/closing `Dialog` components on iOS ([#2635](https://github.com/tailwindlabs/headlessui/pull/2635))
16+
- Don't assume `<Tab />` components are available when setting the next index ([#2642](https://github.com/tailwindlabs/headlessui/pull/2642))
1617

1718
## [1.7.15] - 2023-07-27
1819

packages/@headlessui-vue/src/components/tabs/tabs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ export let TabGroup = defineComponent({
130130
}
131131
)
132132

133-
selectedIndex.value = match(direction, {
133+
let nextSelectedIndex = match(direction, {
134134
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
135135
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
136136
})
137+
if (nextSelectedIndex !== -1) {
138+
selectedIndex.value = nextSelectedIndex
139+
}
137140
api.tabs.value = tabs
138141
api.panels.value = panels
139142
}

0 commit comments

Comments
 (0)