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

[ButtonGroup] Support vertical option #17884

Closed
sasanrasouli opened this issue Oct 15, 2019 · 12 comments · Fixed by #18762
Closed

[ButtonGroup] Support vertical option #17884

sasanrasouli opened this issue Oct 15, 2019 · 12 comments · Fixed by #18762
Labels
component: ButtonGroup The React component. good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@sasanrasouli
Copy link

there is no vertical ButtonGroup in Material UI. how can I change horizontal ButtonGroup to vertical one? Do I make my own Buttons group together with display: 'block'?

@oliviertassinari oliviertassinari added the new feature New feature or request label Oct 15, 2019
@adeelibr
Copy link
Contributor

adeelibr commented Oct 15, 2019

Hi,

I made a demo on codesandbox with a vertical button group.

Code: https://codesandbox.io/s/material-ui-vertical-button-group-o5dgf
Demo: https://o5dgf.csb.app/

Updated:
Code https://codesandbox.io/s/material-ui-vertical-button-group-bu52u
Demo: https://bu52u.csb.app

does this help? @sasanrasouli

@mark-tate
Copy link
Contributor

I pushed up a PR which adds orientation to ButtonGroup, to see what folks think.

@sasanrasouli
Copy link
Author

@adeelibr thank you, dude.

@adeelibr
Copy link
Contributor

If this resolves your issue, can you kindly close this issue? :) @sasanrasouli

@oliviertassinari oliviertassinari added component: ButtonGroup The React component. waiting for 👍 Waiting for upvotes labels Oct 17, 2019
@oliviertassinari
Copy link
Member

I have added the waiting for users upvotes tag. I'm not sure people are looking for such abstraction. So please upvote this issue if you are. We will prioritize our effort based on the number of upvotes.

@oliviertassinari
Copy link
Member

@adeelibr, @slipmat Thanks for the help on this feature request.

@oliviertassinari oliviertassinari changed the title Vertical ButtonGroup Support vertical ButtonGroup Oct 17, 2019
@oliviertassinari oliviertassinari removed the waiting for 👍 Waiting for upvotes label Nov 30, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented Dec 3, 2019

What about something like this?

diff --git a/packages/material-ui/src/ButtonGroup/ButtonGroup.js b/packages/material-ui/src/ButtonGroup/ButtonGroup.js
index 9fb122ae6..7db68a33d 100644
--- a/packages/material-ui/src/ButtonGroup/ButtonGroup.js
+++ b/packages/material-ui/src/ButtonGroup/ButtonGroup.js
@@ -21,6 +21,10 @@ export const styles = theme => ({
   contained: {
     boxShadow: theme.shadows[2],
   },
+  /* Styles applied to the root element if `orientation="vertical"`. */
+  vertical: {
+    flexDirection: 'column',
+  },
   /* Styles applied to the root element if `fullWidth={true}`. */
   fullWidth: {
     width: '100%',
@@ -28,6 +32,9 @@ export const styles = theme => ({
   /* Styles applied to the children. */
   grouped: {
     minWidth: 40,
+  },
+  /* Styles applied to the children if `orientation="horizontal"`. */
+  groupedHorizontal: {
     '&:not(:first-child)': {
       borderTopLeftRadius: 0,
       borderBottomLeftRadius: 0,
@@ -37,14 +44,35 @@ export const styles = theme => ({
       borderBottomRightRadius: 0,
     },
   },
+  /* Styles applied to the children if `orientation="vertical"`. */
+  groupedVertical: {
+    '&:not(:first-child)': {
+      borderTopRightRadius: 0,
+      borderTopLeftRadius: 0,
+    },
+    '&:not(:last-child)': {
+      borderBottomRightRadius: 0,
+      borderBottomLeftRadius: 0,
+    },
+  },
   /* Styles applied to the children if `variant="text"`. */
-  groupedText: {
+  groupedText: {},
+  /* Styles applied to the children if `variant="text"` and `orientation="horizontal"`. */
+  groupedTextHorizontal: {
     '&:not(:last-child)': {
       borderRight: `1px solid ${
         theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'
       }`,
     },
   },
+  /* Styles applied to the children if `variant="text"` and `orientation="vertical"`. */
+  groupedTextVertical: {
+    '&:not(:last-child)': {
+      borderBottom: `1px solid ${
+        theme.palette.type === 'light' ? 'rgba(0, 0, 0, 0.23)' : 'rgba(255, 255, 255, 0.23)'
+      }`,
+    },
+  },
   /* Styles applied to the children if `variant="text"` and `color="primary"`. */
   groupedTextPrimary: {
     '&:not(:last-child)': {
@@ -58,7 +86,9 @@ export const styles = theme => ({
     },
   },
   /* Styles applied to the children if `variant="outlined"`. */
-  groupedOutlined: {
+  groupedOutlined: {},
+  /* Styles applied to the children if `variant="outlined"` and `orientation="horizontal"`. */
+  groupedOutlinedHorizontal: {
     '&:not(:first-child)': {
       marginLeft: -1,
     },
@@ -66,6 +96,15 @@ export const styles = theme => ({
       borderRightColor: 'transparent',
     },
   },
+  /* Styles applied to the children if `variant="outlined"` and `orientation="vertical"`. */
+  groupedOutlinedVertical: {
+    '&:not(:first-child)': {
+      marginTop: -1,
+    },
+    '&:not(:last-child)': {
+      borderBottomColor: 'transparent',
+    },
+  },
   /* Styles applied to the children if `variant="outlined"` and `color="primary"`. */
   groupedOutlinedPrimary: {
     '&:hover': {
@@ -81,6 +120,9 @@ export const styles = theme => ({
   /* Styles applied to the children if `variant="contained"`. */
   groupedContained: {
     boxShadow: 'none',
+  },
+  /* Styles applied to the children if `variant="contained"` and `orientation="horizontal"`. */
+  groupedContainedHorizontal: {
     '&:not(:last-child)': {
       borderRight: `1px solid ${theme.palette.grey[400]}`,
       '&$disabled': {
@@ -88,16 +130,25 @@ export const styles = theme => ({
       },
     },
   },
+  /* Styles applied to the children if `variant="contained"` and `orientation="vertical"`. */
+  groupedContainedVertical: {
+    '&:not(:last-child)': {
+      borderBottom: `1px solid ${theme.palette.grey[400]}`,
+      '&$disabled': {
+        borderBottom: `1px solid ${theme.palette.action.disabled}`,
+      },
+    },
+  },
   /* Styles applied to the children if `variant="contained"` and `color="primary"`. */
   groupedContainedPrimary: {
     '&:not(:last-child)': {
-      borderRight: `1px solid ${theme.palette.primary.dark}`,
+      borderColor: theme.palette.primary.dark,
     },
   },
   /* Styles applied to the children if `variant="contained"` and `color="secondary"`. */
   groupedContainedSecondary: {
     '&:not(:last-child)': {
-      borderRight: `1px solid ${theme.palette.secondary.dark}`,
+      borderColor: theme.palette.secondary.dark,
     },
   },
   /* Pseudo-class applied to child elements if `disabled={true}`. */
@@ -115,6 +166,7 @@ const ButtonGroup = React.forwardRef(function ButtonGroup(props, ref) {
     disableFocusRipple = false,
     disableRipple = false,
     fullWidth = false,
+    orientation = 'horizontal',
     size = 'medium',
     variant = 'outlined',
     ...other
@@ -122,7 +174,9 @@ const ButtonGroup = React.forwardRef(function ButtonGroup(props, ref) {

   const buttonClassName = clsx(
     classes.grouped,
+    classes[`grouped${capitalize(orientation)}`],
     classes[`grouped${capitalize(variant)}`],
+    classes[`grouped${capitalize(variant)}${capitalize(orientation)}`],
     classes[`grouped${capitalize(variant)}${color !== 'default' ? capitalize(color) : ''}`],
     {
       [classes.disabled]: disabled,
@@ -136,6 +190,7 @@ const ButtonGroup = React.forwardRef(function ButtonGroup(props, ref) {
         classes.root,
         {
           [classes.contained]: variant === 'contained',
+          [classes.vertical]: orientation === 'vertical',
           [classes.fullWidth]: fullWidth,
         },
         className,
@@ -214,6 +269,10 @@ ButtonGroup.propTypes = {
    * If `true`, the buttons will take up the full width of its container.
    */
   fullWidth: PropTypes.bool,
+  /**
+   * The group orientation.
+   */
+  orientation: PropTypes.oneOf(['horizontal', 'vertical']),
   /**
    * The size of the button.
    * `small` is equivalent to the dense button styling.

Capture d’écran 2019-12-04 à 00 12 10

@slipmat Do you want to resume your effort? :)

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Dec 3, 2019
@oliviertassinari oliviertassinari changed the title Support vertical ButtonGroup [ButtonGroup] Support vertical option Dec 3, 2019
@SandraMarcelaHerreraArriaga
Copy link
Contributor

@oliviertassinari this issue is working by someone?

@oliviertassinari
Copy link
Member

Not I'm aware of.

@mark-tate
Copy link
Contributor

Sorry, I've been distracted on some other things.
Sandra, if you want to pick this up, your welcome, otherwise, I'm happy to resume.

@SandraMarcelaHerreraArriaga
Copy link
Contributor

@slipmat thank you in a few moments I create pull request of this :)

@simkessy
Copy link

What would be the approach if you want to have icons that are aligned? Right now I have this:

          <ButtonGroup
            orientation="vertical"
            color="primary"
            aria-label="vertical outlined primary button group"
          >
            <Button
              variant="contained"
              color="secondary"
              type="button"
              endIcon={<Add />}
            >
              Add
            </Button>
            <Button color="primary" type="button" endIcon={<Remove />}>
              Remove
            </Button>
          </ButtonGroup>

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonGroup The React component. good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
6 participants