Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7fd628f
`useDidElementMove`: handle `HTMLElement`
RobinMalfait Jul 30, 2024
ffdc6c4
`useResolveButtonType`: handle `HTMLElement`
RobinMalfait Jul 30, 2024
7dedb66
`useRefocusableInput`: handle `HTMLElement`
RobinMalfait Jul 30, 2024
b194e65
`useTransition`: handle `HTMLElement`
RobinMalfait Jul 30, 2024
6f90b1e
ensure `containers` are a dependency of `useEffect`
RobinMalfait Jul 30, 2024
a7bbcee
`Menu`: track `button` and `items` elements in state
RobinMalfait Jul 30, 2024
6298af9
`Combobox`: track `input`, `button` and `options` elements in state
RobinMalfait Aug 1, 2024
ef6afd5
`Disclosure`: track `button` and `panel` elements in state
RobinMalfait Aug 1, 2024
5bd4d58
`Listbox`: track `button` and `options` elements in state
RobinMalfait Aug 1, 2024
d01b25b
`Popover`: track `button` and `panel` elements in state
RobinMalfait Aug 1, 2024
2d14b2c
`Transition`: track the `container` element in state
RobinMalfait Aug 1, 2024
632b2d0
remove incorrect leftover `style=""` attribute
RobinMalfait Jul 30, 2024
477f259
simplify `useDidElementMove`, only accept `HTMLElement | null`
RobinMalfait Aug 1, 2024
6a90d34
pass `HTMLElement | null` directly to `useResolveButtonType`
RobinMalfait Aug 1, 2024
d56dfcf
simplify `useResolveButtonType`, only handle `HTMLElement | null`
RobinMalfait Aug 1, 2024
7128c24
simplify `useRefocusableInput`
RobinMalfait Aug 1, 2024
4d71797
simplify `useElementSize`
RobinMalfait Aug 1, 2024
8d26d4c
simplify `useOutsideClick`
RobinMalfait Aug 1, 2024
7e61373
do not rely on `HTMLButtonElement` being available
RobinMalfait Aug 1, 2024
697468d
update changelog
RobinMalfait Aug 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Popover: track button and panel elements in state
  • Loading branch information
RobinMalfait committed Aug 1, 2024
commit d01b25b86701cebf018c96ef4d1a23f860413118
21 changes: 12 additions & 9 deletions packages/@headlessui-react/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
useFloatingReference(),
isWithinPanel
? null
: (button) => {
: useEvent((button) => {
if (button) {
state.buttons.current.push(uniqueIdentifier)
} else {
Expand All @@ -552,7 +552,7 @@ function ButtonFn<TTag extends ElementType = typeof DEFAULT_BUTTON_TAG>(
}

button && dispatch({ type: ActionTypes.SetButton, button })
}
})
)
let withinPanelButtonRef = useSyncRefs(internalButtonRef, ref)
let ownerDocument = useOwnerDocument(internalButtonRef)
Expand Down Expand Up @@ -763,13 +763,13 @@ function BackdropFn<TTag extends ElementType = typeof DEFAULT_BACKDROP_TAG>(
...theirProps
} = props
let [{ popoverState }, dispatch] = usePopoverContext('Popover.Backdrop')
let internalBackdropRef = useRef<HTMLElement | null>(null)
let backdropRef = useSyncRefs(ref, internalBackdropRef)
let [backdropElement, setBackdropElement] = useState<HTMLElement | null>(null)
let backdropRef = useSyncRefs(ref, setBackdropElement)

let usesOpenClosedState = useOpenClosed()
let [visible, transitionData] = useTransition(
transition,
internalBackdropRef,
backdropElement,
usesOpenClosedState !== null
? (usesOpenClosedState & State.Open) === State.Open
: popoverState === PopoverStates.Open
Expand Down Expand Up @@ -865,9 +865,12 @@ function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(
portal = true
}

let panelRef = useSyncRefs(internalPanelRef, ref, anchor ? floatingRef : null, (panel) => {
dispatch({ type: ActionTypes.SetPanel, panel })
})
let panelRef = useSyncRefs(
internalPanelRef,
ref,
anchor ? floatingRef : null,
useEvent((panel) => dispatch({ type: ActionTypes.SetPanel, panel }))
)
let ownerDocument = useOwnerDocument(internalPanelRef)
let mergeRefs = useMergeRefsFn()

Expand All @@ -881,7 +884,7 @@ function PanelFn<TTag extends ElementType = typeof DEFAULT_PANEL_TAG>(
let usesOpenClosedState = useOpenClosed()
let [visible, transitionData] = useTransition(
transition,
internalPanelRef,
state.panel,
usesOpenClosedState !== null
? (usesOpenClosedState & State.Open) === State.Open
: state.popoverState === PopoverStates.Open
Expand Down