Skip to content

Commit 8bf8936

Browse files
authored
[Layout] Rebuild OptionList with layout primitives (#7958)
### WHY are these changes introduced? Fixes #7952 ### WHAT is this pull request doing? Updates `OptionList` to use new layout primitives. One small visual change with this update due to replacing `margin` with `padding` is a slight increase (`4px`) in spacing when there are multiple sections in an `OptionList`. I don't think the added complexity to keep this the same as current doesn't seem worth it, but happy to hear other thoughts. **Update:** Added a `Bleed` to resolve the spacing change. Feels hacky but prevents the visual change.
1 parent a462c8b commit 8bf8936

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

.changeset/slimy-years-tie.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+
Updated `OptionList` to use new layout primitives

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

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {isSection} from '../../utilities/options';
99
import {arraysAreEqual} from '../../utilities/arrays';
1010
import {useUniqueId} from '../../utilities/unique-id';
1111
import {useDeepEffect} from '../../utilities/use-deep-effect';
12-
import {Box} from '../Box';
12+
import {Box, BoxProps} from '../Box';
1313
import {Text} from '../Text';
14+
import {Bleed} from '../Bleed';
1415

1516
import {Option} from './components';
16-
import styles from './OptionList.scss';
1717

1818
type Alignment = 'top' | 'center' | 'bottom';
1919

@@ -130,24 +130,30 @@ export function OptionList({
130130
});
131131

132132
return (
133-
<li key={title || `noTitle-${sectionIndex}`}>
133+
<Box
134+
key={title || `noTitle-${sectionIndex}`}
135+
as="li"
136+
paddingBlockStart={isFirstOption ? undefined : '2'}
137+
>
134138
{titleMarkup}
135-
<ul
136-
className={styles.Options}
137-
id={`${id}-${sectionIndex}`}
138-
role={role}
139-
>
140-
{optionsMarkup}
141-
</ul>
142-
</li>
139+
<Bleed marginBlockStart={title ? undefined : '05'} marginInline="0">
140+
<Box
141+
as="ul"
142+
id={`${id}-${sectionIndex}`}
143+
role={role as BoxProps['role']}
144+
>
145+
{optionsMarkup}
146+
</Box>
147+
</Bleed>
148+
</Box>
143149
);
144150
})
145151
: null;
146152

147153
return (
148-
<ul className={styles.OptionList} role={role}>
154+
<Box as="ul" role={role as BoxProps['role']} padding="2">
149155
{optionsMarkup}
150-
</ul>
156+
</Box>
151157
);
152158
}
153159

polaris-react/src/components/OptionList/components/Option/Option.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ $control-vertical-adjustment: 2px;
112112
.Media {
113113
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
114114
@include recolor-icon(var(--p-icon));
115-
padding: 0 var(--p-space-2);
116115
}
117116

118117
.verticalAlignTop {

0 commit comments

Comments
 (0)