Skip to content

Commit

Permalink
Don't assume <Tab /> components are available when setting the next…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
RobinMalfait authored Aug 3, 2023
1 parent 6f9de89 commit c22a8c1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use correct value when resetting `<Listbox multiple>` and `<Combobox multiple>` ([#2626](https://github.com/tailwindlabs/headlessui/pull/2626))
- Render `<MainTreeNode />` in `Popover.Group` component only ([#2634](https://github.com/tailwindlabs/headlessui/pull/2634))
- Disable smooth scrolling when opening/closing `Dialog` components on iOS ([#2635](https://github.com/tailwindlabs/headlessui/pull/2635))
- Don't assume `<Tab />` components are available when setting the next index ([#2642](https://github.com/tailwindlabs/headlessui/pull/2642))

## [1.7.16] - 2023-07-27

Expand Down
10 changes: 6 additions & 4 deletions packages/@headlessui-react/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,14 @@ let reducers: {
return nextState
}

let nextSelectedIndex = match(direction, {
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
})

return {
...nextState,
selectedIndex: match(direction, {
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
}),
selectedIndex: nextSelectedIndex === -1 ? state.selectedIndex : nextSelectedIndex,
}
}

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

## [1.7.15] - 2023-07-27

Expand Down
5 changes: 4 additions & 1 deletion packages/@headlessui-vue/src/components/tabs/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ export let TabGroup = defineComponent({
}
)

selectedIndex.value = match(direction, {
let nextSelectedIndex = match(direction, {
[Direction.Forwards]: () => tabs.indexOf(focusableTabs[0]),
[Direction.Backwards]: () => tabs.indexOf(focusableTabs[focusableTabs.length - 1]),
})
if (nextSelectedIndex !== -1) {
selectedIndex.value = nextSelectedIndex
}
api.tabs.value = tabs
api.panels.value = panels
}
Expand Down

2 comments on commit c22a8c1

@vercel
Copy link

@vercel vercel bot commented on c22a8c1 Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-vue – ./packages/playground-vue

headlessui-vue-git-main-tailwindlabs.vercel.app
headlessui-vue-tailwindlabs.vercel.app
headlessui-vue.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c22a8c1 Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

headlessui-react – ./packages/playground-react

headlessui-react.vercel.app
headlessui-react-git-main-tailwindlabs.vercel.app
headlessui-react-tailwindlabs.vercel.app

Please sign in to comment.