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

[Feature]: Access state exposed only via data-attributes #1549

Open
2 tasks
thomasaull opened this issue Jan 9, 2025 · 2 comments
Open
2 tasks

[Feature]: Access state exposed only via data-attributes #1549

thomasaull opened this issue Jan 9, 2025 · 2 comments
Assignees
Labels

Comments

@thomasaull
Copy link

thomasaull commented Jan 9, 2025

Describe the feature

I'm currently implementing Calendar and Date Picker components in a project and I'm not sure how to tackle this problem in the best way possible. To give you an example (please note that this exists in many more places):

  • I have a component MyButton.vue which I want to use as the prev/next buttons for the calendar component
  • MyButton has a prop for a disabled state
  • The CalendarPrev of radix-vue has a state disabled, which is only exposed as a data-attribute [data-disabled]

My question now is, how to handle this case, where the state disabled is only exposed as a data-attribute but I want to forward it to my component as a prop?

Some ideas:

  1. Use both the prop and the data-attribute for styling in the MyButton component (which I don’t really want to do, since the component should stay independent to the parent components implementing it. Also it could introduce additional styling bugs)
  2. Create some sort of composable to reactively read the data attributes from an element
  3. Recreate the behaviour of disabled with my own logic
  4. radix-vue exposes the state in other ways aswell, for example as slots or by making contexts available

Any advice?

Additional information

  • I intend to submit a PR for this feature.
  • I have already implemented and/or tested this feature.
@zernonia zernonia added the v2 label Jan 11, 2025
@zernonia zernonia added this to v2 Jan 11, 2025
@zernonia zernonia moved this to Backlog in v2 Jan 11, 2025
@zernonia
Copy link
Member

Thanks for the ticket @thomasaull ! What do you think if we expose all values from the data-attribute as slot props?

  <Primitive 
    :data-disabled="disabled || undefined"
  >
    <slot :disabled="disabled || undefined">Prev page</slot>
  </Primitive>

@thomasaull
Copy link
Author

@zernonia That‘s exactly how I implemented a workaround in my project, so this would be perfect :)

@zernonia zernonia self-assigned this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Development

No branches or pull requests

2 participants