Trigger scrollIntoView effect when position changes (#1113)
* trigger scrollIntoView effect when position changes This is important otherwise it could happen that the current active item is still the active item even if we inserted X items before the current one. This will result in the active item being out of the current viewport. To fix this, we will also make sure to trigger the effect if the position of the active item changes. * update changelog
This commit is contained in:
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Improve build files ([#1078](https://github.com/tailwindlabs/headlessui/pull/1078))
|
||||
- Ensure typeahead stays on same item if it still matches ([#1098](https://github.com/tailwindlabs/headlessui/pull/1098))
|
||||
- Fix off-by-one frame issue causing flicker ([#1111](https://github.com/tailwindlabs/headlessui/pull/1111))
|
||||
- Trigger scrollIntoView effect when position changes ([#1113](https://github.com/tailwindlabs/headlessui/pull/1113))
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
@@ -860,7 +860,12 @@ function Option<
|
||||
document.getElementById(id)?.scrollIntoView?.({ block: 'nearest' })
|
||||
})
|
||||
return d.dispose
|
||||
}, [id, active, state.comboboxState])
|
||||
}, [
|
||||
id,
|
||||
active,
|
||||
state.comboboxState,
|
||||
/* We also want to trigger this when the position of the active item changes so that we can re-trigger the scrollIntoView */ state.activeOptionIndex,
|
||||
])
|
||||
|
||||
let handleClick = useCallback(
|
||||
(event: { preventDefault: Function }) => {
|
||||
|
||||
@@ -670,7 +670,12 @@ function Option<
|
||||
document.getElementById(id)?.scrollIntoView?.({ block: 'nearest' })
|
||||
})
|
||||
return d.dispose
|
||||
}, [id, active, state.listboxState])
|
||||
}, [
|
||||
id,
|
||||
active,
|
||||
state.listboxState,
|
||||
/* We also want to trigger this when the position of the active item changes so that we can re-trigger the scrollIntoView */ state.activeOptionIndex,
|
||||
])
|
||||
|
||||
let handleClick = useCallback(
|
||||
(event: { preventDefault: Function }) => {
|
||||
|
||||
@@ -539,7 +539,12 @@ function Item<TTag extends ElementType = typeof DEFAULT_ITEM_TAG>(
|
||||
document.getElementById(id)?.scrollIntoView?.({ block: 'nearest' })
|
||||
})
|
||||
return d.dispose
|
||||
}, [id, active, state.menuState])
|
||||
}, [
|
||||
id,
|
||||
active,
|
||||
state.menuState,
|
||||
/* We also want to trigger this when the position of the active item changes so that we can re-trigger the scrollIntoView */ state.activeItemIndex,
|
||||
])
|
||||
|
||||
let bag = useRef<MenuItemDataRef['current']>({ disabled })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user