Skip to content

Commit 9f8b651

Browse files
kyledurandlaurkim
andauthored
Inline remove wrap children in div (#7625)
Part of #7592 Reasons why we don't want to wrap children in div - Unexpected layouts. Passing in an inline element gets renders in a block - Performance. Looping over ever child element to wrap in an extra div can add up. This is also less performant on the client as it adds to the DOM - Argo and other consumers have to do funky things to match this functionality cc @olavoasantos Expected vs unexpected layout: ![image](https://user-images.githubusercontent.com/6844391/199729692-098b5bc0-7617-4561-95e5-556a711883a8.png) Co-authored-by: Lo Kim <lo.kim@shopify.com>
1 parent 79d92a8 commit 9f8b651

File tree

3 files changed

+29
-42
lines changed

3 files changed

+29
-42
lines changed

.changeset/quick-spies-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': patch
3+
---
4+
5+
Removed wrap children with div from Inline component
Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import type {ComponentMeta} from '@storybook/react';
3-
import {Badge, Heading, Icon, Inline} from '@shopify/polaris';
4-
import {CapitalMajor} from '@shopify/polaris-icons';
3+
import {Box, Badge, Heading, Icon, Inline, Thumbnail} from '@shopify/polaris';
4+
import {CapitalMajor, ImageMajor} from '@shopify/polaris-icons';
55

66
export default {
77
component: Inline,
@@ -13,102 +13,104 @@ export function Default() {
1313
<Badge>One</Badge>
1414
<Badge>Two</Badge>
1515
<Badge>Three</Badge>
16-
<Icon source={CapitalMajor} color="primary" />
16+
<Box>
17+
<Icon source={CapitalMajor} color="primary" />
18+
</Box>
1719
</Inline>
1820
);
1921
}
2022

2123
export function AlignYCenter() {
2224
return (
2325
<Inline alignY="center" spacing="1">
26+
<Thumbnail source={ImageMajor} alt="example" />
2427
<Badge>One</Badge>
2528
<Badge>Two</Badge>
2629
<Badge>Three</Badge>
27-
<Icon source={CapitalMajor} color="primary" />
2830
</Inline>
2931
);
3032
}
3133

3234
export function AlignYTop() {
3335
return (
34-
<Inline alignY="top">
36+
<Inline alignY="top" spacing="1">
37+
<Thumbnail source={ImageMajor} alt="example" />
3538
<Badge>One</Badge>
3639
<Badge>Two</Badge>
3740
<Badge>Three</Badge>
38-
<Icon source={CapitalMajor} color="primary" />
3941
</Inline>
4042
);
4143
}
4244

4345
export function AlignYBottom() {
4446
return (
45-
<Inline alignY="bottom">
47+
<Inline alignY="bottom" spacing="1">
48+
<Thumbnail source={ImageMajor} alt="example" />
4649
<Badge>One</Badge>
4750
<Badge>Two</Badge>
4851
<Badge>Three</Badge>
49-
<Icon source={CapitalMajor} color="primary" />
5052
</Inline>
5153
);
5254
}
5355

5456
export function AlignYBaseline() {
5557
return (
56-
<Inline alignY="baseline">
58+
<Inline alignY="baseline" spacing="1">
59+
<Thumbnail source={ImageMajor} alt="example" />
5760
<Badge>One</Badge>
5861
<Badge>Two</Badge>
5962
<Badge>Three</Badge>
60-
<Icon source={CapitalMajor} color="primary" />
6163
</Inline>
6264
);
6365
}
6466

6567
export function AlignStart() {
6668
return (
67-
<Inline align="start">
69+
<Inline align="start" alignY="center" spacing="1">
70+
<Thumbnail source={ImageMajor} alt="example" />
6871
<Badge>One</Badge>
6972
<Badge>Two</Badge>
7073
<Badge>Three</Badge>
71-
<Icon source={CapitalMajor} color="primary" />
7274
</Inline>
7375
);
7476
}
7577

7678
export function AlignCenter() {
7779
return (
78-
<Inline align="center">
80+
<Inline align="center" alignY="center" spacing="1">
81+
<Thumbnail source={ImageMajor} alt="example" />
7982
<Badge>One</Badge>
8083
<Badge>Two</Badge>
8184
<Badge>Three</Badge>
82-
<Icon source={CapitalMajor} color="primary" />
8385
</Inline>
8486
);
8587
}
8688

8789
export function AlignEnd() {
8890
return (
89-
<Inline align="end">
91+
<Inline align="end" alignY="center" spacing="1">
92+
<Thumbnail source={ImageMajor} alt="example" />
9093
<Badge>One</Badge>
9194
<Badge>Two</Badge>
9295
<Badge>Three</Badge>
93-
<Icon source={CapitalMajor} color="primary" />
9496
</Inline>
9597
);
9698
}
9799

98100
export function AlignCenterAlignYCenter() {
99101
return (
100-
<Inline align="center" alignY="center">
102+
<Inline align="center" alignY="center" spacing="1">
103+
<Thumbnail source={ImageMajor} alt="example" />
101104
<Badge>One</Badge>
102105
<Badge>Two</Badge>
103106
<Badge>Three</Badge>
104-
<Icon source={CapitalMajor} color="primary" />
105107
</Inline>
106108
);
107109
}
108110

109111
export function NonWrapping() {
110112
return (
111-
<Inline wrap={false}>
113+
<Inline wrap={false} spacing="1">
112114
<Badge>Paid</Badge>
113115
<Badge>Processing</Badge>
114116
<Badge>Fulfilled</Badge>
@@ -121,23 +123,9 @@ export function Spacing() {
121123
return (
122124
<Inline spacing="8">
123125
<Badge>Paid</Badge>
126+
<Badge>Processing</Badge>
124127
<Badge>Fulfilled</Badge>
125-
</Inline>
126-
);
127-
}
128-
129-
export function VerticalCentering() {
130-
return (
131-
<Inline alignY="center">
132-
<Heading>
133-
Order
134-
<br />
135-
#1136
136-
<br />
137-
was paid
138-
</Heading>
139-
<Badge>Paid</Badge>
140-
<Badge>Fulfilled</Badge>
128+
<Badge>Completed</Badge>
141129
</Inline>
142130
);
143131
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import type {SpacingSpaceScale} from '@shopify/polaris-tokens';
33

4-
import {elementChildren} from '../../utilities/components';
5-
64
import styles from './Inline.scss';
75

86
const AlignY = {
@@ -43,13 +41,9 @@ export const Inline = function Inline({
4341
'--pc-inline-spacing': `var(--p-space-${spacing})`,
4442
} as React.CSSProperties;
4543

46-
const itemMarkup = elementChildren(children).map((child, index) => {
47-
return <div key={index}>{child}</div>;
48-
});
49-
5044
return (
5145
<div className={styles.Inline} style={style}>
52-
{itemMarkup}
46+
{children}
5347
</div>
5448
);
5549
};

0 commit comments

Comments
 (0)