From 8a9867cd5822e3d2c845076cec36f5959ad75e29 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Thu, 14 Mar 2024 22:16:56 +0100 Subject: [PATCH] Accept optional `strategy` for the `anchor` prop (#3034) * accept `strategy` for the `anchor` prop * update changelog --- packages/@headlessui-react/CHANGELOG.md | 4 ++++ packages/@headlessui-react/src/internal/floating.tsx | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/@headlessui-react/CHANGELOG.md b/packages/@headlessui-react/CHANGELOG.md index 1035c32..a3bd3dd 100644 --- a/packages/@headlessui-react/CHANGELOG.md +++ b/packages/@headlessui-react/CHANGELOG.md @@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Attempt form submission when pressing `Enter` on the `` component ([#2972](https://github.com/tailwindlabs/headlessui/pull/2972)) +### Added + +- Accept optional `strategy` for the `anchor` prop ([#3034](https://github.com/tailwindlabs/headlessui/pull/3034)) + ## [2.0.0-alpha.4] - 2024-01-03 ### Fixed diff --git a/packages/@headlessui-react/src/internal/floating.tsx b/packages/@headlessui-react/src/internal/floating.tsx index b14a638..2aeea1b 100644 --- a/packages/@headlessui-react/src/internal/floating.tsx +++ b/packages/@headlessui-react/src/internal/floating.tsx @@ -21,6 +21,11 @@ type Align = 'start' | 'end' type Placement = 'top' | 'right' | 'bottom' | 'left' type BaseAnchorProps = { + /** + * The strategy to use when positioning the panel. Defaults to `fixed`. + */ + strategy: 'absolute' | 'fixed' + /** * The `gap` is the space between the trigger and the panel. */ @@ -166,6 +171,7 @@ export function FloatingProvider({ offset = 0, padding = 0, inner, + strategy = 'fixed', } = useResolvedConfig(config, floatingEl) let [to, align = 'center'] = placement.split(' ') as [Placement | 'selection', Align | 'center'] @@ -189,7 +195,7 @@ export function FloatingProvider({ // This component will be used in combination with a `Portal`, which means the floating // element will be rendered outside of the current DOM tree. - strategy: 'fixed', + strategy, // We use the panel in a `Dialog` which is making the page inert, therefore no re-positioning is // needed when scrolling changes.