question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[ToggleButton] Provide unstyled/headless API for heavy customization

See original GitHub 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.

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, 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 #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.
1reaction
mnajdovacommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[ToggleButton] Provide unstyled/headless API for ... - GitHub
I'd like to style a to look and behave exactly like a without explicitly overriding all of the ToggleButton's class styles.
Read more >
Toggle Buttons - Android Developers
A toggle button allows the user to change a setting between two states. You can add a basic toggle button to your layout...
Read more >
Blazor ToggleButton Overview - Documentation - Telerik
The Toggle Button provides several parameters that control its styling and appearance, including background color, shape, rounded corners and fill.
Read more >
Mui pagination. jsx Framework css. Features Supports rtl, you ...
The MUI TablePagination component is a dynamic and highly customizable component. ... [ToggleButton] Provide unstyled/headless API for heavy customization ...
Read more >
ToggleButton API - Material UI - MUI
The name MuiToggleButton can be used when providing default props or style overrides in the theme. Props. Props of the ButtonBase component are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found