Skip to content

Commit a2eca1d

Browse files
[ButtonGroup] Add optional nowrap property to ButtonGroup (#8033)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> This PR is non-breaking and adds an optional noWrap property to the ButtonGroup component which prevents the buttons in a ButtonGroup from wrapping onto a new line. This change will help with alignment issues we have been having on the new Metaobjects Index page encountered with very long Metaobject Type names. <img width="556" alt="Screenshot 2023-01-11 at 4 13 12 PM" src="https://user-images.githubusercontent.com/109357057/211918907-9632b84b-1f32-4b5b-80d4-75b2130f0022.png"> A `noWrap` option will allow for the title object to wrap sooner instead of forcing the action buttons onto 2 lines. ### WHY are these changes introduced? To address alignment issues on the new Metaobjects page. Since we want our buttons in line with our Metaobjects `Type` label (which might be long), we would prefer to set the `ButtonGroup` to `noWrap` and force the label to wrap. <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? <!-- Summary of the changes committed. Before / after screenshots are appreciated for UI changes. Make sure to include alt text that describes the screenshot. If you include an animated gif showing your change, wrapping it in a details tag is recommended. Gifs usually autoplay, which can cause accessibility issues for people reviewing your PR: <details> <summary>Summary of your gif(s)</summary> <img src="..." alt="Description of what the gif shows"> </details> --> ### 🎩 checklist - [x] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [x] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [ ] Updated the component's `README.md` with documentation changes - [ ] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 4b470fc commit a2eca1d

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.changeset/happy-dragons-repair.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Added an optional `noWrap` prop to `ButtonGroup`

polaris-react/src/components/ButtonGroup/ButtonGroup.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,8 @@
9090
margin-left: var(--p-space-5);
9191
}
9292
}
93+
94+
.noWrap {
95+
display: flex;
96+
flex-wrap: nowrap;
97+
}

polaris-react/src/components/ButtonGroup/ButtonGroup.stories.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,43 @@ export function OutlineWithSegmentedButtons() {
3434
</ButtonGroup>
3535
);
3636
}
37+
38+
export function NoWrapButtons() {
39+
return (
40+
<>
41+
<p>Default</p>
42+
<div
43+
style={{
44+
width: '300px',
45+
border: '2px solid blue',
46+
padding: '10px',
47+
overflowX: 'scroll',
48+
}}
49+
>
50+
<ButtonGroup>
51+
<Button>Fourth</Button>
52+
<Button>Third</Button>
53+
<Button>Second</Button>
54+
<Button primary>First</Button>
55+
</ButtonGroup>
56+
</div>
57+
<br />
58+
<p>With noWrap</p>
59+
<div
60+
style={{
61+
width: '300px',
62+
border: '2px solid blue',
63+
padding: '10px',
64+
overflowX: 'scroll',
65+
}}
66+
>
67+
<ButtonGroup noWrap>
68+
<Button>Fourth</Button>
69+
<Button>Third</Button>
70+
<Button>Second</Button>
71+
<Button primary>First</Button>
72+
</ButtonGroup>
73+
</div>
74+
</>
75+
);
76+
}

polaris-react/src/components/ButtonGroup/ButtonGroup.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface ButtonGroupProps {
1717
fullWidth?: boolean;
1818
/** Remove top left and right border radius */
1919
connectedTop?: boolean;
20+
/** Prevent buttons in button group from wrapping to next line */
21+
noWrap?: boolean;
2022
/** Button components */
2123
children?: React.ReactNode;
2224
}
@@ -27,12 +29,14 @@ export function ButtonGroup({
2729
segmented,
2830
fullWidth,
2931
connectedTop,
32+
noWrap,
3033
}: ButtonGroupProps) {
3134
const className = classNames(
3235
styles.ButtonGroup,
3336
spacing && styles[spacing],
3437
segmented && styles.segmented,
3538
fullWidth && styles.fullWidth,
39+
noWrap && styles.noWrap,
3640
);
3741

3842
const contents = elementChildren(children).map((child, index) => (
@@ -45,6 +49,7 @@ export function ButtonGroup({
4549
data-buttongroup-segmented={segmented}
4650
data-buttongroup-connected-top={connectedTop}
4751
data-buttongroup-full-width={fullWidth}
52+
data-buttongroup-no-wrap={noWrap}
4853
>
4954
{contents}
5055
</div>

0 commit comments

Comments
 (0)