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

Dialog uses open/closed state from Context over props #1308

Closed
jaredpereira opened this issue Apr 7, 2022 · 4 comments · Fixed by #1360
Closed

Dialog uses open/closed state from Context over props #1308

jaredpereira opened this issue Apr 7, 2022 · 4 comments · Fixed by #1360

Comments

@jaredpereira
Copy link

jaredpereira commented Apr 7, 2022

What package within Headless UI are you using?
@headlessui/react

What version of that package are you using?
1.5.0

Reproduction URL
https://codesandbox.io/s/headless-bug-repro-3fz4dz?file=/src/App.js

Hi!
I ran into this when triggering a Dialog to open from inside a Disclosure component. It was a little surprising as the docs say

Dialogs have no automatic management of their open/closed state.

In any case this seems to be where the passed in value is getting over ridden if I am understanding the code correctly.

I think the best course of action is to remove all references to usesOpenClosedState but if not, preferring the passed in value makes sense!

let visible = (() => {
if (usesOpenClosedState !== null) {
return usesOpenClosedState === State.Open
}
return dialogState === DialogStates.Open
})()

@RobinMalfait
Copy link
Member

Hey! Thank you for your bug report!
Much appreciated! 🙏

This is indeed a bug and we should prefer local props over context information. The reason this exists is to make Transitions easier. Here is an example: https://headlessui.dev/react/menu#transitions

Currently working on React 18 compatibility so this won't be fixed immediately.

@gusflopes
Copy link

Run into the same bug.
I'm using these packages:
"@headlessui/react": "^1.5.0"
"next": "12.1.4",
"react": "^18.0.0",
"react-dom": "^18.0.0",

The dropdown that uses Disclosure components won't work unless i change reactStrictMode to false on next.config.js:
Seems to be related to compatibility issue after updating to React 18.

Should we keep using React 17 for now? Just following this issue for now.

@RobinMalfait
Copy link
Member

RobinMalfait commented Apr 13, 2022

@gusflopes you are describing a React 18 issue, checkout the pinned issue #681. I'm also confused about what you mean with a "Dropdown" that uses the "Disclosure" component 🤔

@RobinMalfait
Copy link
Member

Hey! Thank you for your bug report!
Much appreciated! 🙏

This should be fixed by #1360, and will be available in the next release.

You can already try it using:

  • npm install @headlessui/react@insiders or yarn add @headlessui/react@insiders.
  • npm install @headlessui/vue@insiders or yarn add @headlessui/vue@insiders.

Here is an updated CodeSandbox: https://codesandbox.io/s/headless-bug-repro-forked-29kf0e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants