Skip to content

Commit 85c0220

Browse files
authored
[Box] Add support for overflowX, overflowY, and width props (#7432)
### WHY are these changes introduced? While rebuilding the `Modal` component with our layout primitives, I came across gaps that our layout components don't yet support. We have no way of handling content overflow and while we did ship a PR to add `maxWidth` support to `Box`, we should also support `width`. ### WHAT is this pull request doing? - Adds `width` prop - Adds `overflowX` and `overflowY` with type definition limited to `hidden` or `scroll` after discussions with @sarahill - Removes `px` from being interpolated in the `maxWidth` prop because these could be percentages <!-- ℹ️ Delete the following for small / trivial changes --> ### How to 🎩 🖥 [Local development instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development) 🗒 [General tophatting guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md) 📄 [Changelog guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog) <!-- Give as much information as needed to experiment with the component in the playground. --> <details> <summary>Copy-paste this code in <code>playground/Playground.tsx</code>:</summary> ```jsx import React from 'react'; import {Page} from '../src'; export function Playground() { return ( <Page title="Playground"> {/* Add the code you want to test in here */} </Page> ); } ``` </details> ### 🎩 checklist - [ ] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [ ] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [ ] 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 80e1648 commit 85c0220

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

.changeset/kind-carrots-leave.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 support for `overflowX`, `overflowY`, and `width` props to `Box`

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
--pc-box-border-top: initial;
1313
--pc-box-color: initial;
1414
--pc-box-max-width: initial;
15+
--pc-box-overflow-x: initial;
16+
--pc-box-overflow-y: initial;
1517
--pc-box-padding-bottom: initial;
1618
--pc-box-padding-left: initial;
1719
--pc-box-padding-right: initial;
1820
--pc-box-padding-top: initial;
21+
--pc-box-width: initial;
1922
background-color: var(--pc-box-background);
2023
box-shadow: var(--pc-box-shadow);
2124
border-bottom-left-radius: var(--pc-box-border-radius-bottom-left);
@@ -28,9 +31,13 @@
2831
border-top: var(--pc-box-border-top);
2932
color: var(--pc-box-color);
3033
max-width: var(--pc-box-max-width);
34+
overflow-x: var(--pc-box-overflow-x);
35+
overflow-y: var(--pc-box-overflow-y);
3136
padding-bottom: var(--pc-box-padding-bottom);
3237
padding-left: var(--pc-box-padding-left);
3338
padding-right: var(--pc-box-padding-right);
3439
padding-top: var(--pc-box-padding-top);
40+
width: var(--pc-box-width);
3541
/* stylelint-enable declaration-block-no-redundant-longhand-properties */
42+
-webkit-overflow-scrolling: touch;
3643
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import styles from './Box.scss';
1010

1111
type Element = 'div' | 'span';
1212

13+
type Overflow = 'hidden' | 'scroll';
14+
1315
export type BackgroundColorTokenScale =
1416
| 'action-critical'
1517
| 'action-critical-depressed'
@@ -164,8 +166,12 @@ export interface BoxProps {
164166
color?: ColorTokenScale;
165167
/** HTML id attribute */
166168
id?: string;
167-
/** Spacing outside of container */
169+
/** Set maximum width of container */
168170
maxWidth?: string;
171+
/** Clip horizontal content of children */
172+
overflowX?: Overflow;
173+
/** Clip vertical content of children */
174+
overflowY?: Overflow;
169175
/** Spacing around children */
170176
padding?: SpacingSpaceScale;
171177
/** Bottom spacing around children */
@@ -178,6 +184,8 @@ export interface BoxProps {
178184
paddingTop?: SpacingSpaceScale;
179185
/** Shadow */
180186
shadow?: DepthShadowAlias;
187+
/** Set width of container */
188+
width?: string;
181189
}
182190

183191
export const Box = forwardRef<HTMLElement, BoxProps>(
@@ -199,12 +207,15 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
199207
color,
200208
id,
201209
maxWidth,
210+
overflowX,
211+
overflowY,
202212
padding,
203213
paddingBottom,
204214
paddingLeft,
205215
paddingRight,
206216
paddingTop,
207217
shadow,
218+
width,
208219
},
209220
ref,
210221
) => {
@@ -270,7 +281,9 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
270281
}
271282
: undefined),
272283
...(color ? {'--pc-box-color': `var(--p-${color})`} : undefined),
273-
...(maxWidth ? {'--pc-box-max-width': `${maxWidth}px`} : undefined),
284+
...(maxWidth ? {'--pc-box-max-width': `${maxWidth}`} : undefined),
285+
...(overflowX ? {'--pc-box-overflow-x': `${overflowX}`} : undefined),
286+
...(overflowY ? {'--pc-box-overflow-y': `${overflowY}`} : undefined),
274287
...(paddings.bottom
275288
? {'--pc-box-padding-bottom': `var(--p-space-${paddings.bottom})`}
276289
: undefined),
@@ -286,6 +299,7 @@ export const Box = forwardRef<HTMLElement, BoxProps>(
286299
...(shadow
287300
? {'--pc-box-shadow': `var(--p-shadow-${shadow})`}
288301
: undefined),
302+
...(width ? {'--pc-box-max-width': `${width}`} : undefined),
289303
} as React.CSSProperties;
290304

291305
const className = classNames(styles.Box);

0 commit comments

Comments
 (0)