Closed unional closed 1 month ago
I think the first question we need to answer is, what is the use case here? Is it just visual regression testing?
My use case is visual regression testing, as well as specification and documentation. I want the engineer and designer going to our website and storybook to see exactly how the component should look like on various state. And also have it match the Figma defined by the design system team.
In terms of code and consistency, it is also nice and natural to see what you defined shows up on the DOM for data-*
, just like aria-*
attributes.
In terms of code and consistency, at it also nice and natural to see what you defined shows up on the DOM for data-, just like aria- attributes.
But this isn't true, we control many aria-* attributes, so if you send them in as props, they may or may not come out on the other side and they may be merged/altered. That's a majority of the reason for this library.
I don't think consistency applies here as we are consistent in our handling of these. We have certain properties that we are going to apply regardless of what a user tries to send it. Right now, that applies to a certain set of documented data-* attributes we consider to be API.
It seems like I somehow didn't mentioned that specifying data-hover
in @headlessui/react
works as expected. It is also using react-aria
under the hood.
It appears they are using React Aria, not React Aria Components https://github.com/tailwindlabs/headlessui/blob/main/packages/%40headlessui-react/src/components/button/button.tsx
React Aria isn't responsible for dealing with the data- attributes, that's not part of its API. So you could build your own components from the hooks and make the data- attributes whatever you like.
I'm going to close this issue as working as intended. I think we can continue discussions over on https://github.com/adobe/react-spectrum/issues/6403 if there's more as I believe that's really what you're trying to do.
Provide a general summary of the issue here
When setting the data attribute prop
data-hovered
, the prop is eaten and not showing up in the DOM element.๐ค Expected Behavior?
<Button data-hovered/>
should yield<button data-hovered/>
๐ฏ Current Behavior
<Button data-hovered/>
yields<button/>
๐ Possible Solution
Haven't look into the code, but likely there is a spread
const { 'data-hovered': dataHovered, ...rest } = props
and missing<button data-hovered={dataHovered}/>
another possibility is that since those data-attributes are managed by rac, a merge is missing to honor the initial values.
๐ฆ Context
This make it not possible to set the hover state without some hack/workaround.
This could be the root cause of #6198 #4411
Related to #6522 #6403
๐ฅ๏ธ Steps to Reproduce
codesandbox
In the repro, you can see that
data-hover
is being recognized:This is because
data-hover
is not a data attribute managed byreact-aria-components
. So the prop is added to the DOM:When hovering on the one with
data-hovered
CSS, it is working. i.e.:hover
is applyingdata-hovered
(anddata-focused
) correctly:But looking at the first button you will see the
data-hovered
prop is missing:while the code defined it:
As a side note, setting element state from dev tool doesn't work:
That's probably a limitation to the data-attribute approach, I guess.
Version
react-aria-components: 1.3.1
What browsers are you seeing the problem on?
Chrome
If other, please specify.
No response
What operating system are you using?
macOS
๐งข Your Company/Team
Palo Alto Networks
๐ท Tracking Issue
No response