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

Add some render features + render strategy #106

Merged
merged 15 commits into from
Oct 18, 2020
Merged

Conversation

RobinMalfait
Copy link
Collaborator

@RobinMalfait RobinMalfait commented Oct 15, 2020

Currently we already have a static prop feature for the Menu Items and Listbox Options. The static option means that we don't show/hide those components based on the state. The user is in control. This can be handy if you want to add transition components around it so that you can transition and delay the unmounting.

This PR will introduce a render strategy for certain components.

  • Features:
    • Static The user is in control
    • RenderStrategy
      • Unmount Unmount the tree
      • Hidden Hide the tree with the hidden prop and style="display: none;"

We also made sure that the TypeScript types are XOR.

  • This is valid: <Menu.Items />
  • This is valid: <Menu.Items unmount />
  • This is valid: <Menu.Items unmount={false} />
  • This is valid: <Menu.Items static />
  • This is not valid: <Menu.Items unmount static />

This will fix #44

For the transition component the same rules will apply: <Transition unmount={false} /> and <Transition.Child unmount={false} /> will keep everything in the DOM instead of unmounting.

@vercel
Copy link

vercel bot commented Oct 15, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

headlessui-react – ./packages/@headlessui-react

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/2h5pjg9gy
✅ Preview: https://headlessui-react-git-render-strategy.tailwindlabs.vercel.app

headlessui-vue – ./packages/@headlessui-vue

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/5lnfwhxb2
✅ Preview: https://headlessui-vue-git-render-strategy.tailwindlabs.vercel.app

Example use case:

```tsx
// Some components have this API with an `innerRef`. The suggested approach is to use
// `React.forwardRef` so that you get the actual `ref` value. However if you already have this
// `innerRef` API than we can use the `refName="innerRef"` to give the `ref` prop a good name. It
// defaults to `ref` so that it still works everywhere else.

function MyButton({ innerRef, ...props }) {
  return <button ref={innerRef} {...props} />
}

<Menu.Button as={MyButton} refName="innerRef" />
```
+ use the unique __ symbol as a default value in the Props type for the
  omitable props.
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 this pull request may close these issues.

Elements with Transition not in DOM until show is true
1 participant