Material-ui: [ToggleButton] Incorrect styling for adjacent, selected, vertical buttons

Created on 27 Sep 2020  路  2Comments  路  Source: mui-org/material-ui


ToggleButton modifies the styles of adjacent, selected ToggleButtons:

export const styles = (theme) => ({
  /* Styles applied to the root element. */
  root: {
    '&$selected': {
      '& + &': {
        borderLeft: 0,
        marginLeft: 0,
      },
    }
  }
}

This styling is intended for the horizontal orientation, but is also being applied to the vertical orientation. Also, the equivalent styling for vertical (i.e. for borderTop and marginTop) is missing.

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸


The net effect is that when there are adjacent, selected, vertical buttons, the selected buttons after the first selected button are missing their left borders and the top borders are slightly thicker/darker than they should be.

Expected Behavior 馃


The borders for selected vertical buttons should have the same appearance as horizontal apart from the orientation change.

Steps to Reproduce 馃暪

Here is a v4 sandbox based on one of the demos that reproduces the problem: https://codesandbox.io/s/togglebutton-selected-border-issue-j1m2c?file=/demo.js

Here is a similar sandbox but using current v5: https://codesandbox.io/s/togglebutton-selected-border-issue-v5-0kf3q?file=/demo.js

You can see that the left border of the second vertical button is missing and the top border of that same button is thicker/darker than the equivalent border between the first two horizontal buttons.

Context 馃敠


This issue was brought to my attention by this StackOverflow question.

The workaround that I provided in my answer was the following:

const ToggleButtonGroup = withStyles((theme) => ({
  groupedVertical: {
    "&&.Mui-selected + &&.Mui-selected": {
      borderLeft: `1px solid ${fade(theme.palette.action.active, 0.12)}`,
      borderTop: 0,
      marginTop: 0
    }
  }
}))(MuiToggleButtonGroup);

The real fix should probably remove the horizontal-specific styling from ToggleButton and instead control it in ToggleButtonGroup in an orientation-specific fashion. Alternatively, it could still be done in ToggleButton, but orientation would need to be passed from ToggleButtonGroup so that the styles can be orientation-specific.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v5.0.0-alpha.11 (also v4.11.0) |

bug 馃悰 ToggleButton good to take

Most helpful comment

Hi @ryancogswell and @oliviertassinari , can I take this issue.

All 2 comments

The real fix should probably remove the horizontal-specific styling from ToggleButton and instead control it in ToggleButtonGroup in an orientation-specific fashion.

It sounds like a great solution.

Hi @ryancogswell and @oliviertassinari , can I take this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

activatedgeek picture activatedgeek  路  3Comments

revskill10 picture revskill10  路  3Comments

pola88 picture pola88  路  3Comments

rbozan picture rbozan  路  3Comments

ryanflorence picture ryanflorence  路  3Comments