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

[RFC][base-ui][Switch] The input component should be opt-in #40618

Closed
DiegoAndai opened this issue Jan 15, 2024 · 4 comments
Closed

[RFC][base-ui][Switch] The input component should be opt-in #40618

DiegoAndai opened this issue Jan 15, 2024 · 4 comments
Assignees
Labels
component: switch This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base RFC Request For Comments

Comments

@DiegoAndai
Copy link
Member

DiegoAndai commented Jan 15, 2024

What's the problem?

The docs and demos related to the Switch component include the hidden checkbox input. This is not a common pattern when building Switch components, and it might be confusing.

What are the requirements?

Simplify the switch component and hook for the base use case.

What are our options?

  • Keep it as is
  • Make the input opt-out
  • Make the input opt-in

Proposed solution

The input component should be opt-in, meaning:

  • the useSwitch hook should work without it. The input component is helpful for form submission so that I wouldn't remove it, but it's not a common enough use case to have it by default.
  • The Switch component shouldn't include the input by default
  • The docs and demos shouldn't include the input. There should be a separate demo for adding the input for the specified use case

Resources and benchmarks

Search keywords:

@DiegoAndai DiegoAndai added component: switch This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base RFC Request For Comments labels Jan 15, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Base UI Jan 15, 2024
@Nikhilh26
Copy link
Contributor

Nikhilh26 commented Jan 25, 2024

hey ! i would like to contribute to this but i am unable to reproduce and check on my local system to verify the changes i have made are solving the problem or not. Can you guide me on this. Thanks!

@DiegoAndai
Copy link
Member Author

DiegoAndai commented Jan 25, 2024

Hi @Nikhilh26, thanks for the interest. This RFC has no decision yet, so the following steps are unclear. In other words, the issue is not ready to be worked on. I recommend looking for issues with the ready to take label instead.

@michaldudak
Copy link
Member

We used to have a similar discussion around the Select. At first, the hidden input was rendered only when the name prop was present (to participate in form submission), but we ended up needing it for more than this (built-in browser form validation, autofill), so now it's always rendered.
I think the Switch should behave the same way. The checkbox doesn't necessarily have to be styled, but IMO it should be present.

@DiegoAndai
Copy link
Member Author

Fair enough. I did a proper benchmark, and other unstyled libraries have it as well:

In any case we're missing the switch role, but that's the topic for #40615 so I'm closing this.

@github-project-automation github-project-automation bot moved this from Backlog to Done in Base UI Jan 30, 2024
@michaldudak michaldudak removed this from Base UI Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: switch This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

3 participants