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

[ToggleButton] Create the unstyled component and hook #11

Open
Tracked by #10
dungle-scrubs opened this issue May 9, 2021 · 5 comments
Open
Tracked by #10

[ToggleButton] Create the unstyled component and hook #11

dungle-scrubs opened this issue May 9, 2021 · 5 comments
Labels
component: toggle button This is the name of the generic UI component, not the React module! new feature New feature or request

Comments

@dungle-scrubs
Copy link

I'd like to style a <ToggleButton> to look and behave exactly like a <Button> without explicitly overriding all of the ToggleButton's class styles.

I've learned that I can inject Button styles this way:

<ToggleButton
  classes={{
    root: 'MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedSecondary MuiButton-disableElevation',
    selected: 'MuiButton-root:hover MuiButton-containedSecondary:hover MuiButton-disableElevation:active MuiButton-disableElevation:hover MuiButton-contained:active MuiButton-contained:hover',
  }}
>

This halfway solves my problem. However, I'd like to avoid injecting the classes MuiToggleButton-root MuiToggleButtonGroup-grouped MuiToggleButtonGroup-groupedHorizontal because they're overriding the ones I've added above.

Is this sort of thing possible? The reason I'm trying this is because I can't put a <Button> inside of a <ToggleButton> without getting an error, so I figured I'd try to make it look and behave like a <Button>.

Thanks

@dungle-scrubs dungle-scrubs added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 9, 2021
@mnajdova
Copy link
Member

I don't quite understand the issue.

I'd like to style a <ToggleButton> to look and behave exactly like a <Button> without explicitly overriding all of the ToggleButton's class styles.

If you like it to behave like a Button, why don't you use the Button?

Is the use-case that you would like to actually use a ToggleButton that looks like Button? What about the toggled state?
It would partially be possible to do this once we have unstyled version of this component, once we have it.

@dungle-scrubs
Copy link
Author

@mnajdova Thanks, sorry I forgot to clarify something. I'm using ToggleButton for radio-button-like functionality, but I need the radios to look exactly like <Button>, including hover and active states.

I couldn't get Mui's <Radio> to style like a <Button> so I'm trying to use <ToggleButton> instead. However, I get an error when using <Button> inside of <ToggleButton>.

Does that make sense?

@mnajdova
Copy link
Member

mnajdova commented May 10, 2021

Got it yes, sounds like something that will be possible with the unstyled components. Until then, we don’t have option to reset styles.

@dungle-scrubs
Copy link
Author

Thanks for clearing that up and looking forward to that. Until then, manually restyling isn't too big of a deal.

@oliviertassinari oliviertassinari removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 11, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented May 11, 2021

This makes me think about:

  1. ButtonGroup and ToggleButton are very close in UI. We could have almost built ToggleButton on top of ButtonGroup.
  2. ToggleButton adds functionality over ButtonGroup. In [Lab] Improve accessibility of ToggleButton and ToggleButtonGroup material-ui#17203 we explore how to improve the a11y.
  3. Maybe we could extract the ToggleButton behavior into a headless hook, and expose it, which would allow @dungle-scrubs to implement the same behavior with a Button. I doubt that an unstyled component API would work for this use case.
  4. Reading https://www.w3.org/TR/wai-aria-practices/examples/toolbar/toolbar.html, the hook we need might even be at the radio level, not sure.

@oliviertassinari oliviertassinari changed the title Option to remove injected .Mui[component] styling? [ToggleButton] Provide unstyled/headless API for heavy customization May 11, 2021
@mnajdova mnajdova changed the title [ToggleButton] Provide unstyled/headless API for heavy customization [base][ToggleButton] Provide unstyled/headless API for heavy customization Apr 17, 2023
@michaldudak michaldudak changed the title [base][ToggleButton] Provide unstyled/headless API for heavy customization [ToggleButton][base] Create the unstyled component and hook Jul 19, 2023
@michaldudak michaldudak changed the title [ToggleButton][base] Create the unstyled component and hook [ToggleButton][base-ui] Create the unstyled component and hook Aug 18, 2023
@michaldudak michaldudak transferred this issue from mui/material-ui Feb 27, 2024
@michaldudak michaldudak changed the title [ToggleButton][base-ui] Create the unstyled component and hook [ToggleButton] Create the unstyled component and hook Feb 27, 2024
@michaldudak michaldudak added new feature New feature or request component: toggle button This is the name of the generic UI component, not the React module! labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: toggle button This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

4 participants