Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Disclosure.Panel is properly linked #1747

Merged
merged 2 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/@headlessui-react/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix incorrect scrolling to the bottom when opening a `Dialog` ([#1716](https://github.com/tailwindlabs/headlessui/pull/1716))
- Make form components uncontrollable ([#1683](https://github.com/tailwindlabs/headlessui/pull/1683))
- Improve `Combobox` re-opening keyboard issue on mobile ([#1732](https://github.com/tailwindlabs/headlessui/pull/1732))
- Ensure `Disclosure.Panel` is properly linked ([#1747](https://github.com/tailwindlabs/headlessui/pull/1747))

## Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,8 @@ let Panel = forwardRefWithAs(function Panel<TTag extends ElementType = typeof DE
let [state, dispatch] = useDisclosureContext('Disclosure.Panel')
let { close } = useDisclosureAPIContext('Disclosure.Panel')

let panelRef = useSyncRefs(ref, state.panelRef, () => {
if (state.linkedPanel) return
dispatch({ type: ActionTypes.LinkPanel })
let panelRef = useSyncRefs(ref, state.panelRef, (el) => {
dispatch({ type: el ? ActionTypes.LinkPanel : ActionTypes.UnlinkPanel })
})

let usesOpenClosedState = useOpenClosed()
Expand All @@ -374,16 +373,6 @@ let Panel = forwardRefWithAs(function Panel<TTag extends ElementType = typeof DE
return state.disclosureState === DisclosureStates.Open
})()

// Unlink on "unmount" myself
useEffect(() => () => dispatch({ type: ActionTypes.UnlinkPanel }), [dispatch])

// Unlink on "unmount" children
useEffect(() => {
if (state.disclosureState === DisclosureStates.Closed && (props.unmount ?? true)) {
dispatch({ type: ActionTypes.UnlinkPanel })
}
}, [state.disclosureState, props.unmount, dispatch])

let slot = useMemo<PanelRenderPropArg>(
() => ({ open: state.disclosureState === DisclosureStates.Open, close }),
[state, close]
Expand Down