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

Only add type=button for real buttons #709

Merged
merged 2 commits into from
Aug 2, 2021

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jul 30, 2021

We naively put type: button on certain components because the default component is a button. However, when somebody uses the as prop with a different component like div, then adding a type of button results in weird/incorrect behaviour.

This PR will check what the actual rendered DOM element is, and if it is a button without a type, only then will we apply a type of button.

Fixes: #619

@vercel
Copy link

vercel bot commented Jul 30, 2021

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/GJRcGAfyfZtzfTXBUbDaMcJRELMn
✅ Preview: https://headlessui-react-git-resolve-button-type-correctly-tailwindlabs.vercel.app

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

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/37Wj7MELJHaAvqrXrq7yBY6bZYCm
✅ Preview: https://headlessui-vue-git-resolve-button-type-correctly-tailwindlabs.vercel.app

We will try and infer the type based on the passed in `props.as` prop or
the default tag. However, when somebody uses `as={CustomComponent}` then
we don't know what it will render. Therefore we have to pass it a ref
and check if the final result is a button or not. If it is, and it
doesn't have a `type` yet, then we can set the `type` correctly.
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.

1 participant