Prefer incoming data-*
attributes, over the ones set by Headless UI
#3035
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Typically when Headless UI components set certain props on a component, then they are there to make sure that the component behaves as expected. E.g.:
aria-*
attributes,role
attributes,tabIndex
, etc.However, we also provide helpful
data-focus
ordata-hover
attributes that make styling components easier. These attributes are not necessary to make the component behave as expected.This brings us to the problem that this PR solves. Sometimes when you use one of Headless UI's components, and you provide your own component that already contains the same
data-*
attributes, then your attributes will be overridden.This PR solves that and prefers the existing
data-*
attributes over the ones we set in Headless UI.This is currently only implemented when you can't really control the props when using
as={Fragment}
.In this scenario the
data-hover
based on thehovered
variable that can come from anywhere will be preferred compared to whatMenuButton
provides.