Skip to content

Commit 0dfd5f9

Browse files
committed
fix(list): use container heights and the expand token for the chevron
1 parent d0a3478 commit 0dfd5f9

8 files changed

Lines changed: 157 additions & 65 deletions

File tree

‎src/components/List/ListAccordion.tsx‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,6 @@ const ListAccordion = ({
212212
setIsDescriptionMultiline(nativeEvent.lines.length >= 2);
213213
};
214214

215-
const getVerticalPaddingStyle = () => {
216-
if (!description) {
217-
return styles.containerOneLine;
218-
}
219-
220-
return isDescriptionMultiline
221-
? styles.containerThreeLine
222-
: styles.containerTwoLine;
223-
};
224-
225215
const handlePressAction = (e: GestureResponderEvent) => {
226216
onPress?.(e);
227217

@@ -257,7 +247,11 @@ const ListAccordion = ({
257247
style={{ backgroundColor: theme.colors[ListTokens.containerColor] }}
258248
>
259249
<TouchableRipple
260-
style={[styles.container, getVerticalPaddingStyle(), style]}
250+
style={[
251+
styles.container,
252+
description ? styles.containerTwoLine : styles.containerOneLine,
253+
style,
254+
]}
261255
onPress={handlePress}
262256
onLongPress={onLongPress}
263257
delayLongPress={delayLongPress}
@@ -323,7 +317,7 @@ const ListAccordion = ({
323317
) : (
324318
<MaterialCommunityIcon
325319
name={isExpanded ? 'chevron-up' : 'chevron-down'}
326-
color={theme.colors[ListTokens.trailingIconColor]}
320+
color={theme.colors[ListTokens.expandTrailingIconColor]}
327321
size={24}
328322
direction={direction}
329323
/>
@@ -358,16 +352,15 @@ ListAccordion.displayName = 'List.Accordion';
358352

359353
const styles = StyleSheet.create({
360354
container: {
355+
paddingVertical: ListTokens.verticalPadding,
361356
paddingRight: ListTokens.trailingSpace,
357+
justifyContent: 'center',
362358
},
363359
containerOneLine: {
364-
paddingVertical: ListTokens.oneLineVerticalPadding,
360+
minHeight: ListTokens.oneLineContainerHeight,
365361
},
366362
containerTwoLine: {
367-
paddingVertical: ListTokens.twoLineVerticalPadding,
368-
},
369-
containerThreeLine: {
370-
paddingVertical: ListTokens.threeLineVerticalPadding,
363+
minHeight: ListTokens.twoLineContainerHeight,
371364
},
372365
row: {
373366
flexDirection: 'row',

‎src/components/List/ListItem.tsx‎

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,6 @@ const ListItem = ({
172172
setIsDescriptionMultiline(nativeEvent.lines.length >= 2);
173173
};
174174

175-
const getVerticalPaddingStyle = () => {
176-
if (!description) {
177-
return styles.containerOneLine;
178-
}
179-
180-
return isDescriptionMultiline
181-
? styles.containerThreeLine
182-
: styles.containerTwoLine;
183-
};
184-
185175
const renderDescription = (
186176
descriptionColor: ColorValue,
187177
description?: Description | null
@@ -240,7 +230,11 @@ const ListItem = ({
240230
<TouchableRipple
241231
{...rest}
242232
ref={ref}
243-
style={[styles.container, getVerticalPaddingStyle(), style]}
233+
style={[
234+
styles.container,
235+
description ? styles.containerTwoLine : styles.containerOneLine,
236+
style,
237+
]}
244238
onPress={onPress}
245239
theme={theme}
246240
testID={testID}
@@ -277,16 +271,15 @@ ListItem.displayName = 'List.Item';
277271

278272
const styles = StyleSheet.create({
279273
container: {
274+
paddingVertical: ListTokens.verticalPadding,
280275
paddingRight: ListTokens.trailingSpace,
276+
justifyContent: 'center',
281277
},
282278
containerOneLine: {
283-
paddingVertical: ListTokens.oneLineVerticalPadding,
279+
minHeight: ListTokens.oneLineContainerHeight,
284280
},
285281
containerTwoLine: {
286-
paddingVertical: ListTokens.twoLineVerticalPadding,
287-
},
288-
containerThreeLine: {
289-
paddingVertical: ListTokens.threeLineVerticalPadding,
282+
minHeight: ListTokens.twoLineContainerHeight,
290283
},
291284
row: {
292285
width: '100%',

‎src/components/List/tokens.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { ColorRole } from '../../theme/types';
22

33
const sizes = {
4-
oneLineVerticalPadding: 16,
5-
twoLineVerticalPadding: 14,
6-
threeLineVerticalPadding: 12,
4+
verticalPadding: 12,
5+
oneLineContainerHeight: 56,
6+
twoLineContainerHeight: 72,
77
leadingSpace: 16,
88
trailingSpace: 16,
99
} as const;
@@ -14,6 +14,7 @@ const colors = {
1414
supportingTextColor: 'onSurfaceVariant',
1515
leadingIconColor: 'onSurfaceVariant',
1616
trailingIconColor: 'onSurfaceVariant',
17+
expandTrailingIconColor: 'onSurface',
1718
} as const satisfies Record<string, ColorRole>;
1819

1920
export const ListTokens = { ...sizes, ...colors };

‎src/components/__tests__/ListAccordion.test.tsx‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,20 @@ describe('ListAccordion', () => {
144144
});
145145
});
146146

147-
it('drops to 12dp padding once the description wraps to a third line', async () => {
147+
it('hits the container heights without measuring the description', async () => {
148+
await render(
149+
<ListAccordion title="Accordion item 1" testID="list-accordion">
150+
<ListItem title="List item 1" />
151+
</ListAccordion>
152+
);
153+
154+
expect(screen.getByTestId('list-accordion')).toHaveStyle({
155+
minHeight: 56,
156+
paddingVertical: 12,
157+
});
158+
});
159+
160+
it('keeps the two line container height once a description is present', async () => {
148161
await render(
149162
<ListAccordion
150163
title="Accordion item 1"
@@ -156,7 +169,8 @@ describe('ListAccordion', () => {
156169
);
157170

158171
expect(screen.getByTestId('list-accordion')).toHaveStyle({
159-
paddingVertical: 14,
172+
minHeight: 72,
173+
paddingVertical: 12,
160174
});
161175

162176
await fireEvent(
@@ -166,10 +180,25 @@ describe('ListAccordion', () => {
166180
);
167181

168182
expect(screen.getByTestId('list-accordion')).toHaveStyle({
183+
minHeight: 72,
169184
paddingVertical: 12,
170185
});
171186
});
172187

188+
it('uses the expand token for the chevron', async () => {
189+
await render(
190+
<ListAccordion title="Accordion item 1">
191+
<ListItem title="List item 1" />
192+
</ListAccordion>
193+
);
194+
195+
expect(
196+
screen.getByText('chevron-down', { includeHiddenElements: true })
197+
).toHaveStyle({
198+
color: getTheme().colors.onSurface,
199+
});
200+
});
201+
173202
it('applies the theme override to title and description typography', async () => {
174203
await render(
175204
<ListAccordion

‎src/components/__tests__/ListItem.test.tsx‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,16 @@ it('renders list item with custom content style', async () => {
176176
expect(screen.getByTestId('list-item-content')).toHaveStyle(styles.content);
177177
});
178178

179-
it('drops to 12dp padding once the description wraps to a third line', async () => {
179+
it('hits the one line container height without measuring the description', async () => {
180+
await render(<ListItem title="First Item" testID={testID} />);
181+
182+
expect(screen.getByTestId(testID)).toHaveStyle({
183+
minHeight: 56,
184+
paddingVertical: 12,
185+
});
186+
});
187+
188+
it('hits the two and three line container heights without measuring', async () => {
180189
await render(
181190
<ListItem
182191
title="First Item"
@@ -185,13 +194,42 @@ it('drops to 12dp padding once the description wraps to a third line', async ()
185194
/>
186195
);
187196

188-
expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 14 });
197+
expect(screen.getByTestId(testID)).toHaveStyle({
198+
minHeight: 72,
199+
paddingVertical: 12,
200+
});
189201

190202
await fireEvent(screen.getByText('Item description'), 'textLayout', {
191203
nativeEvent: { lines: [{}, {}] },
192204
});
193205

194-
expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 12 });
206+
expect(screen.getByTestId(testID)).toHaveStyle({
207+
minHeight: 72,
208+
paddingVertical: 12,
209+
});
210+
});
211+
212+
it('top aligns the accessories once the description wraps', async () => {
213+
await render(
214+
<ListItem
215+
title="First Item"
216+
description="Item description"
217+
left={(props) => <View testID="left-accessory" style={props.style} />}
218+
testID={testID}
219+
/>
220+
);
221+
222+
expect(screen.getByTestId('left-accessory')).toHaveStyle({
223+
alignSelf: 'center',
224+
});
225+
226+
await fireEvent(screen.getByText('Item description'), 'textLayout', {
227+
nativeEvent: { lines: [{}, {}] },
228+
});
229+
230+
expect(screen.getByTestId('left-accessory')).toHaveStyle({
231+
alignSelf: 'flex-start',
232+
});
195233
});
196234

197235
it('applies the theme override to title and description typography', async () => {

‎src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ exports[`renders expanded accordion 1`] = `
4747
},
4848
[
4949
{
50+
"justifyContent": "center",
5051
"paddingRight": 16,
52+
"paddingVertical": 12,
5153
},
5254
{
53-
"paddingVertical": 16,
55+
"minHeight": 56,
5456
},
5557
undefined,
5658
],
@@ -131,7 +133,7 @@ exports[`renders expanded accordion 1`] = `
131133
style={
132134
[
133135
{
134-
"color": "rgba(73, 69, 79, 1)",
136+
"color": "rgba(29, 27, 32, 1)",
135137
"fontSize": 24,
136138
},
137139
[
@@ -191,10 +193,12 @@ exports[`renders expanded accordion 1`] = `
191193
false,
192194
[
193195
{
196+
"justifyContent": "center",
194197
"paddingRight": 16,
198+
"paddingVertical": 12,
195199
},
196200
{
197-
"paddingVertical": 16,
201+
"minHeight": 56,
198202
},
199203
undefined,
200204
],
@@ -313,10 +317,12 @@ exports[`renders list accordion with children 1`] = `
313317
},
314318
[
315319
{
320+
"justifyContent": "center",
316321
"paddingRight": 16,
322+
"paddingVertical": 12,
317323
},
318324
{
319-
"paddingVertical": 16,
325+
"minHeight": 56,
320326
},
321327
undefined,
322328
],
@@ -444,7 +450,7 @@ exports[`renders list accordion with children 1`] = `
444450
style={
445451
[
446452
{
447-
"color": "rgba(73, 69, 79, 1)",
453+
"color": "rgba(29, 27, 32, 1)",
448454
"fontSize": 24,
449455
},
450456
[
@@ -519,10 +525,12 @@ exports[`renders list accordion with custom title and description styles 1`] = `
519525
},
520526
[
521527
{
528+
"justifyContent": "center",
522529
"paddingRight": 16,
530+
"paddingVertical": 12,
523531
},
524532
{
525-
"paddingVertical": 14,
533+
"minHeight": 72,
526534
},
527535
undefined,
528536
],
@@ -640,7 +648,7 @@ exports[`renders list accordion with custom title and description styles 1`] = `
640648
style={
641649
[
642650
{
643-
"color": "rgba(73, 69, 79, 1)",
651+
"color": "rgba(29, 27, 32, 1)",
644652
"fontSize": 24,
645653
},
646654
[
@@ -715,10 +723,12 @@ exports[`renders list accordion with left items 1`] = `
715723
},
716724
[
717725
{
726+
"justifyContent": "center",
718727
"paddingRight": 16,
728+
"paddingVertical": 12,
719729
},
720730
{
721-
"paddingVertical": 16,
731+
"minHeight": 56,
722732
},
723733
undefined,
724734
],
@@ -846,7 +856,7 @@ exports[`renders list accordion with left items 1`] = `
846856
style={
847857
[
848858
{
849-
"color": "rgba(73, 69, 79, 1)",
859+
"color": "rgba(29, 27, 32, 1)",
850860
"fontSize": 24,
851861
},
852862
[
@@ -921,10 +931,12 @@ exports[`renders multiline list accordion 1`] = `
921931
},
922932
[
923933
{
934+
"justifyContent": "center",
924935
"paddingRight": 16,
936+
"paddingVertical": 12,
925937
},
926938
{
927-
"paddingVertical": 14,
939+
"minHeight": 72,
928940
},
929941
undefined,
930942
],
@@ -1038,7 +1050,7 @@ exports[`renders multiline list accordion 1`] = `
10381050
style={
10391051
[
10401052
{
1041-
"color": "rgba(73, 69, 79, 1)",
1053+
"color": "rgba(29, 27, 32, 1)",
10421054
"fontSize": 24,
10431055
},
10441056
[

0 commit comments

Comments
 (0)