From bb55033fb32e1643221ff2cf65a2105c3e8c4d8a Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 7 Aug 2026 12:24:00 +0200 Subject: [PATCH 01/16] refactor: align List tokens, spacing and typography with MD3 --- src/components/List/ListAccordion.tsx | 64 ++--- src/components/List/ListItem.tsx | 48 ++-- src/components/List/tokens.ts | 18 ++ src/components/List/utils.ts | 87 +----- .../__tests__/ListAccordion.test.tsx | 47 ++-- .../__snapshots__/ListAccordion.test.tsx.snap | 253 ++++++++--------- .../__snapshots__/ListItem.test.tsx.snap | 260 ++++++++++-------- .../__snapshots__/ListSection.test.tsx.snap | 144 +++++----- 8 files changed, 437 insertions(+), 484 deletions(-) create mode 100644 src/components/List/tokens.ts diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 43314743bd..c143944edb 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -13,8 +13,9 @@ import type { import { ListAccordionContext } from './ListAccordionContext'; import { ListAccordionGroupContext } from './ListAccordionGroup'; -import type { Style } from './utils'; -import { getAccordionColors, getLeftStyles } from './utils'; +import { ListTokens } from './tokens'; +import type { ListChildProps, Style } from './utils'; +import { getLeftStyles } from './utils'; import { useLocale } from '../../core/locale'; import { useInternalTheme } from '../../core/theming'; import type { ThemeProp } from '../../theme/types'; @@ -230,10 +231,8 @@ const ListAccordion = ({ ? groupContext.expandedId === id : expandedInternal; - const { descriptionColor, titleTextColor } = getAccordionColors({ - theme, - isExpanded, - }); + const titleTextColor = theme.colors[ListTokens.headlineColor]; + const descriptionColor = theme.colors[ListTokens.supportingTextColor]; const handlePress = groupContext && id !== undefined @@ -245,12 +244,15 @@ const ListAccordion = ({ return ( - + {left ? left({ - color: isExpanded ? theme.colors?.primary : descriptionColor, + color: theme.colors[ListTokens.leadingIconColor], style: getLeftStyles(alignToTop, description), }) : null} {description ? ( ) : null} - + {right ? ( right({ isExpanded: isExpanded, @@ -319,7 +316,7 @@ const ListAccordion = ({ ) : ( @@ -342,29 +339,22 @@ ListAccordion.displayName = 'List.Accordion'; const styles = StyleSheet.create({ container: { - paddingVertical: 8, - paddingRight: 24, + paddingRight: ListTokens.trailingSpace, }, - row: { - flexDirection: 'row', - marginVertical: 6, - }, - multiline: { - height: 40, - alignItems: 'center', - justifyContent: 'center', + containerOneLine: { + paddingVertical: ListTokens.oneLineVerticalPadding, }, - title: { - fontSize: 16, + containerTwoLine: { + paddingVertical: ListTokens.twoLineVerticalPadding, }, - description: { - fontSize: 14, + row: { + flexDirection: 'row', }, contentItem: { - paddingLeft: 16, + paddingLeft: ListTokens.leadingSpace, }, trailingItem: { - marginVertical: 6, + alignSelf: 'center', paddingLeft: 8, }, content: { diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 659abf9774..c962f14a87 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -10,7 +10,7 @@ import type { ViewStyle, } from 'react-native'; -import { ListAccordionContext } from './ListAccordionContext'; +import { ListTokens } from './tokens'; import { getLeftStyles, getRightStyles } from './utils'; import type { Style } from './utils'; import { useInternalTheme } from '../../core/theming'; @@ -184,18 +184,15 @@ const ListItem = ({ selectable: false, ellipsizeMode: descriptionEllipsizeMode, color: descriptionColor, - fontSize: styles.description.fontSize, + fontSize: theme.fonts.bodyMedium.fontSize, }) ) : ( @@ -205,21 +202,22 @@ const ListItem = ({ }; const renderTitle = () => { - const titleColor = theme.colors.onSurface; + const titleColor = theme.colors[ListTokens.headlineColor]; return typeof title === 'function' ? ( title({ selectable: false, ellipsizeMode: titleEllipsizeMode, color: titleColor, - fontSize: styles.title.fontSize, + fontSize: theme.fonts.bodyLarge.fontSize, }) ) : ( {title} @@ -227,7 +225,7 @@ const ListItem = ({ ); }; - const descriptionColor = theme.colors.onSurfaceVariant; + const descriptionColor = theme.colors[ListTokens.supportingTextColor]; return ( ; + +export const ListTokens = { ...sizes, ...colors }; diff --git a/src/components/List/utils.ts b/src/components/List/utils.ts index 25e5ccd1d1..296acc4e4e 100644 --- a/src/components/List/utils.ts +++ b/src/components/List/utils.ts @@ -1,7 +1,7 @@ -import { StyleSheet } from 'react-native'; -import type { ColorValue, StyleProp, TextProps, ViewStyle } from 'react-native'; +import type { StyleProp, TextProps, ViewStyle } from 'react-native'; -import type { InternalTheme, ThemeProp } from '../../theme/types'; +import { ListTokens } from './tokens'; +import type { ThemeProp } from '../../theme/types'; type Description = | React.ReactNode @@ -26,82 +26,21 @@ export type Style = { alignSelf?: 'flex-start' | 'center'; }; -const stylesV3Left = { - marginRight: 0, - marginLeft: 16, -}; - -const stylesV3Right = { - marginLeft: 16, -}; - -export const getLeftStyles = ( - alignToTop: boolean, - description: Description -) => { - const stylesV3: Style = { - ...stylesV3Left, - alignSelf: alignToTop ? 'flex-start' : 'center', - }; - - if (!description) { - return { - ...styles.iconMarginLeft, - ...styles.marginVerticalNone, - ...stylesV3, - }; - } - - return { - ...styles.iconMarginLeft, - ...stylesV3, - }; -}; - -export const getRightStyles = ( +const getAccessoryStyles = ( alignToTop: boolean, description: Description -) => { - const stylesV3: Style = { - ...stylesV3Right, +): Style => { + const style: Style = { + marginLeft: ListTokens.leadingSpace, + marginRight: 0, alignSelf: alignToTop ? 'flex-start' : 'center', }; - if (!description) { - return { - ...styles.iconMarginRight, - ...styles.marginVerticalNone, - ...stylesV3, - }; - } - - return { - ...styles.iconMarginRight, - ...stylesV3, - }; + return description ? style : { ...style, marginVertical: 0 }; }; -const styles = StyleSheet.create({ - marginVerticalNone: { marginVertical: 0 }, - iconMarginLeft: { marginLeft: 0, marginRight: 16 }, - iconMarginRight: { marginRight: 0 }, -}); +export const getLeftStyles = (alignToTop: boolean, description: Description) => + getAccessoryStyles(alignToTop, description); -export const getAccordionColors = ({ - theme, - isExpanded, -}: { - theme: InternalTheme; - isExpanded?: boolean; -}): { descriptionColor: ColorValue; titleTextColor: ColorValue } => { - const titleColor = theme.colors.onSurface; - - const descriptionColor = theme.colors.onSurfaceVariant; - - const titleTextColor = isExpanded ? theme.colors?.primary : titleColor; - - return { - descriptionColor, - titleTextColor, - }; -}; +export const getRightStyles = (alignToTop: boolean, description: Description) => + getAccessoryStyles(alignToTop, description); diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 4d594e7bd0..9a13e34e6a 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -2,6 +2,7 @@ import { StyleSheet, View } from 'react-native'; import { describe, expect, it } from '@jest/globals'; +import { getTheme } from '../../core/theming'; import { render, screen } from '../../test-utils'; import { red500 } from '../../theme/colors'; import { LightTheme } from '../../theme/schemes'; @@ -9,7 +10,6 @@ import ListAccordion from '../List/ListAccordion'; import ListAccordionGroup from '../List/ListAccordionGroup'; import ListIcon from '../List/ListIcon'; import ListItem from '../List/ListItem'; -import { getAccordionColors } from '../List/utils'; const styles = StyleSheet.create({ coloring: { @@ -164,39 +164,28 @@ describe('ListAccordion', () => { 'List.Accordion is used inside a List.AccordionGroup without specifying an id prop.' ); }); -}); -describe('getAccordionColors - description color', () => { - it('should return theme color, for theme version 3', () => { - expect( - getAccordionColors({ - theme: LightTheme, - }) - ).toMatchObject({ - descriptionColor: LightTheme.colors.onSurfaceVariant, - }); - }); -}); + it('keeps the title on onSurface when collapsed', async () => { + await render( + + + + ); -describe('getAccordionColors - title text color', () => { - it('should return theme color, for theme version 3', () => { - expect( - getAccordionColors({ - theme: LightTheme, - }) - ).toMatchObject({ - titleTextColor: LightTheme.colors.onSurface, + expect(screen.getByText('Accordion item 1')).toHaveStyle({ + color: getTheme().colors.onSurface, }); }); - it('should return primary color if it is expanded', () => { - expect( - getAccordionColors({ - theme: LightTheme, - isExpanded: true, - }) - ).toMatchObject({ - titleTextColor: LightTheme.colors?.primary, + it('keeps the title on onSurface when expanded', async () => { + await render( + + + + ); + + expect(screen.getByText('Accordion item 1')).toHaveStyle({ + color: getTheme().colors.onSurface, }); }); }); diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 5e73775c72..004dbda69e 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -48,7 +48,9 @@ exports[`renders expanded accordion 1`] = ` [ { "paddingRight": 24, - "paddingVertical": 8, + }, + { + "paddingVertical": 16, }, undefined, ], @@ -61,7 +63,6 @@ exports[`renders expanded accordion 1`] = ` [ { "flexDirection": "row", - "marginVertical": 6, }, undefined, ] @@ -91,21 +92,22 @@ exports[`renders expanded accordion 1`] = ` }, { "color": "rgba(29, 27, 32, 1)", - "fontFamily": "System", - "fontWeight": "400", - "letterSpacing": 0, - }, - { "writingDirection": "ltr", }, [ { + "fontFamily": "System", "fontSize": 16, + "fontWeight": "400", + "letterSpacing": 0.5, + "lineHeight": 24, }, - { - "color": "rgba(103, 80, 164, 1)", - }, - undefined, + [ + { + "color": "rgba(29, 27, 32, 1)", + }, + undefined, + ], ], ] } @@ -115,13 +117,10 @@ exports[`renders expanded accordion 1`] = ` Date: Wed, 19 Aug 2026 16:19:26 +0200 Subject: [PATCH 02/16] fix: propagate theme override and add three-line padding to List --- src/components/List/ListAccordion.tsx | 28 +++++++---- src/components/List/ListItem.tsx | 37 +++++++++------ src/components/List/tokens.ts | 1 + .../__tests__/ListAccordion.test.tsx | 47 ++++++++++++++++++- src/components/__tests__/ListItem.test.tsx | 36 +++++++++++++- 5 files changed, 124 insertions(+), 25 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index c143944edb..8a218c427b 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -202,11 +202,22 @@ const ListAccordion = ({ const [expanded, setExpanded] = React.useState( expandedProp || false ); - const [alignToTop, setAlignToTop] = React.useState(false); + const [isDescriptionMultiline, setIsDescriptionMultiline] = + React.useState(false); const onDescriptionTextLayout = (event: TextLayoutEvent) => { const { nativeEvent } = event; - setAlignToTop(nativeEvent.lines.length >= 2); + setIsDescriptionMultiline(nativeEvent.lines.length >= 2); + }; + + const getVerticalPaddingStyle = () => { + if (!description) { + return styles.containerOneLine; + } + + return isDescriptionMultiline + ? styles.containerThreeLine + : styles.containerTwoLine; }; const handlePressAction = (e: GestureResponderEvent) => { @@ -248,11 +259,7 @@ const ListAccordion = ({ style={{ backgroundColor: theme.colors[ListTokens.containerColor] }} > { const theme = useInternalTheme(themeOverrides); - const { hasLeft } = React.useContext(ListAccordionContext); - const shouldIndent = hasLeft && !left && !right; - const [alignToTop, setAlignToTop] = React.useState(false); + const [isDescriptionMultiline, setIsDescriptionMultiline] = + React.useState(false); const onDescriptionTextLayout = (event: TextLayoutEvent) => { const { nativeEvent } = event; - setAlignToTop(nativeEvent.lines.length >= 2); + setIsDescriptionMultiline(nativeEvent.lines.length >= 2); + }; + + const getVerticalPaddingStyle = () => { + if (!description) { + return styles.containerOneLine; + } + + return isDescriptionMultiline + ? styles.containerThreeLine + : styles.containerTwoLine; }; const renderDescription = ( @@ -189,6 +198,7 @@ const ListItem = ({ ) : ( {left ? left({ - color: descriptionColor, - style: getLeftStyles(alignToTop, description), + color: theme.colors[ListTokens.leadingIconColor], + style: getLeftStyles(isDescriptionMultiline, description), }) : null} @@ -258,8 +265,8 @@ const ListItem = ({ {right ? right({ - color: descriptionColor, - style: getRightStyles(alignToTop, description), + color: theme.colors[ListTokens.trailingIconColor], + style: getRightStyles(isDescriptionMultiline, description), }) : null} @@ -279,8 +286,8 @@ const styles = StyleSheet.create({ containerTwoLine: { paddingVertical: ListTokens.twoLineVerticalPadding, }, - indent: { - paddingLeft: 40, + containerThreeLine: { + paddingVertical: ListTokens.threeLineVerticalPadding, }, row: { width: '100%', diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts index 329060c127..c753764bfa 100644 --- a/src/components/List/tokens.ts +++ b/src/components/List/tokens.ts @@ -3,6 +3,7 @@ import type { ColorRole } from '../../theme/types'; const sizes = { oneLineVerticalPadding: 16, twoLineVerticalPadding: 14, + threeLineVerticalPadding: 12, leadingSpace: 16, trailingSpace: 24, } as const; diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 9a13e34e6a..0adeb8c25d 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -3,7 +3,7 @@ import { StyleSheet, View } from 'react-native'; import { describe, expect, it } from '@jest/globals'; import { getTheme } from '../../core/theming'; -import { render, screen } from '../../test-utils'; +import { fireEvent, render, screen } from '../../test-utils'; import { red500 } from '../../theme/colors'; import { LightTheme } from '../../theme/schemes'; import ListAccordion from '../List/ListAccordion'; @@ -188,4 +188,49 @@ describe('ListAccordion', () => { color: getTheme().colors.onSurface, }); }); + + it('drops to 12dp padding once the description wraps to a third line', async () => { + await render( + + + + ); + + expect(screen.getByTestId('list-accordion')).toHaveStyle({ + paddingVertical: 14, + }); + + await fireEvent( + screen.getByText('Describes the expandable list item'), + 'textLayout', + { nativeEvent: { lines: [{}, {}] } } + ); + + expect(screen.getByTestId('list-accordion')).toHaveStyle({ + paddingVertical: 12, + }); + }); + + it('applies the theme override to title and description typography', async () => { + await render( + + + + ); + + expect(screen.getByText('Accordion item 1')).toHaveStyle({ fontSize: 99 }); + expect(screen.getByText('Describes the expandable list item')).toHaveStyle({ + fontSize: 77, + }); + }); }); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 98e6e0f0fe..b7d9c3323c 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -5,7 +5,7 @@ import { Text, View } from 'react-native'; import { expect, it, jest } from '@jest/globals'; import { userEvent } from '@testing-library/react-native'; -import { render, screen } from '../../test-utils'; +import { fireEvent, render, screen } from '../../test-utils'; import { red500 } from '../../theme/colors'; import Chip from '../Chip/Chip'; import IconButton from '../IconButton/IconButton'; @@ -177,3 +177,37 @@ it('renders list item with custom content style', async () => { expect(toJSON()).toMatchSnapshot(); }); + +it('drops to 12dp padding once the description wraps to a third line', async () => { + await render( + + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 14 }); + + await fireEvent(screen.getByText('Item description'), 'textLayout', { + nativeEvent: { lines: [{}, {}] }, + }); + + expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 12 }); +}); + +it('applies the theme override to title and description typography', async () => { + await render( + + ); + + expect(screen.getByText('First Item')).toHaveStyle({ fontSize: 99 }); + expect(screen.getByText('Item description')).toHaveStyle({ fontSize: 77 }); +}); From 0be324bc3718b342b0ee1383eaef7fc388c37721 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Wed, 19 Aug 2026 17:39:38 +0200 Subject: [PATCH 03/16] fix: use 16dp trailing inset to match MD3 --- src/components/List/tokens.ts | 2 +- .../__snapshots__/ListAccordion.test.tsx.snap | 12 ++++++------ .../__tests__/__snapshots__/ListItem.test.tsx.snap | 14 +++++++------- .../__snapshots__/ListSection.test.tsx.snap | 12 ++++++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts index c753764bfa..4a9e7d7c14 100644 --- a/src/components/List/tokens.ts +++ b/src/components/List/tokens.ts @@ -5,7 +5,7 @@ const sizes = { twoLineVerticalPadding: 14, threeLineVerticalPadding: 12, leadingSpace: 16, - trailingSpace: 24, + trailingSpace: 16, } as const; const colors = { diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 004dbda69e..460faf181d 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -47,7 +47,7 @@ exports[`renders expanded accordion 1`] = ` }, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -163,7 +163,7 @@ exports[`renders expanded accordion 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -284,7 +284,7 @@ exports[`renders list accordion with children 1`] = ` }, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -490,7 +490,7 @@ exports[`renders list accordion with custom title and description styles 1`] = ` }, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, @@ -686,7 +686,7 @@ exports[`renders list accordion with left items 1`] = ` }, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -892,7 +892,7 @@ exports[`renders multiline list accordion 1`] = ` }, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap index 716c311748..f0939d9d7a 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap @@ -122,7 +122,7 @@ exports[`renders list item with custom description 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, @@ -485,7 +485,7 @@ exports[`renders list item with custom title and description styles 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, @@ -604,7 +604,7 @@ exports[`renders list item with left and right items 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, @@ -768,7 +768,7 @@ exports[`renders list item with left item 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -897,7 +897,7 @@ exports[`renders list item with right item 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -982,7 +982,7 @@ exports[`renders list item with title and description 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, @@ -1097,7 +1097,7 @@ exports[`renders with a description with typeof number 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 14, diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap index 8adbe4ad34..60b77c96a7 100644 --- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap @@ -460,7 +460,7 @@ exports[`renders list section with custom title style 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -586,7 +586,7 @@ exports[`renders list section with custom title style 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -1166,7 +1166,7 @@ exports[`renders list section with subheader 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -1292,7 +1292,7 @@ exports[`renders list section with subheader 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -1832,7 +1832,7 @@ exports[`renders list section without subheader 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, @@ -1958,7 +1958,7 @@ exports[`renders list section without subheader 1`] = ` false, [ { - "paddingRight": 24, + "paddingRight": 16, }, { "paddingVertical": 16, From 6e66e6408d7023c6aa98f0036262e76f278ff52a Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 28 Aug 2026 17:26:46 +0200 Subject: [PATCH 04/16] fix: use container heights in List and the expand token for the chevron --- src/components/List/ListAccordion.tsx | 27 +++++------- src/components/List/ListItem.tsx | 25 ++++------- src/components/List/tokens.ts | 7 +-- .../__tests__/ListAccordion.test.tsx | 33 +++++++++++++- src/components/__tests__/ListItem.test.tsx | 44 +++++++++++++++++-- .../__snapshots__/ListAccordion.test.tsx.snap | 34 +++++++++----- .../__snapshots__/ListItem.test.tsx.snap | 28 +++++++++--- .../__snapshots__/ListSection.test.tsx.snap | 24 +++++++--- 8 files changed, 157 insertions(+), 65 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 8a218c427b..4bf688ecb5 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -210,16 +210,6 @@ const ListAccordion = ({ setIsDescriptionMultiline(nativeEvent.lines.length >= 2); }; - const getVerticalPaddingStyle = () => { - if (!description) { - return styles.containerOneLine; - } - - return isDescriptionMultiline - ? styles.containerThreeLine - : styles.containerTwoLine; - }; - const handlePressAction = (e: GestureResponderEvent) => { onPress?.(e); @@ -259,7 +249,11 @@ const ListAccordion = ({ style={{ backgroundColor: theme.colors[ListTokens.containerColor] }} > @@ -348,16 +342,15 @@ ListAccordion.displayName = 'List.Accordion'; const styles = StyleSheet.create({ container: { + paddingVertical: ListTokens.verticalPadding, paddingRight: ListTokens.trailingSpace, + justifyContent: 'center', }, containerOneLine: { - paddingVertical: ListTokens.oneLineVerticalPadding, + minHeight: ListTokens.oneLineContainerHeight, }, containerTwoLine: { - paddingVertical: ListTokens.twoLineVerticalPadding, - }, - containerThreeLine: { - paddingVertical: ListTokens.threeLineVerticalPadding, + minHeight: ListTokens.twoLineContainerHeight, }, row: { flexDirection: 'row', diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 36d0dbd413..7ca2967e27 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -174,16 +174,6 @@ const ListItem = ({ setIsDescriptionMultiline(nativeEvent.lines.length >= 2); }; - const getVerticalPaddingStyle = () => { - if (!description) { - return styles.containerOneLine; - } - - return isDescriptionMultiline - ? styles.containerThreeLine - : styles.containerTwoLine; - }; - const renderDescription = ( descriptionColor: ColorValue, description?: Description | null @@ -244,7 +234,11 @@ const ListItem = ({ focusRing="inward" {...rest} ref={ref} - style={[styles.container, getVerticalPaddingStyle(), style]} + style={[ + styles.container, + description ? styles.containerTwoLine : styles.containerOneLine, + style, + ]} onPress={onPress} theme={theme} testID={testID} @@ -278,16 +272,15 @@ ListItem.displayName = 'List.Item'; const styles = StyleSheet.create({ container: { + paddingVertical: ListTokens.verticalPadding, paddingRight: ListTokens.trailingSpace, + justifyContent: 'center', }, containerOneLine: { - paddingVertical: ListTokens.oneLineVerticalPadding, + minHeight: ListTokens.oneLineContainerHeight, }, containerTwoLine: { - paddingVertical: ListTokens.twoLineVerticalPadding, - }, - containerThreeLine: { - paddingVertical: ListTokens.threeLineVerticalPadding, + minHeight: ListTokens.twoLineContainerHeight, }, row: { width: '100%', diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts index 4a9e7d7c14..e67a604812 100644 --- a/src/components/List/tokens.ts +++ b/src/components/List/tokens.ts @@ -1,9 +1,9 @@ import type { ColorRole } from '../../theme/types'; const sizes = { - oneLineVerticalPadding: 16, - twoLineVerticalPadding: 14, - threeLineVerticalPadding: 12, + verticalPadding: 12, + oneLineContainerHeight: 56, + twoLineContainerHeight: 72, leadingSpace: 16, trailingSpace: 16, } as const; @@ -14,6 +14,7 @@ const colors = { supportingTextColor: 'onSurfaceVariant', leadingIconColor: 'onSurfaceVariant', trailingIconColor: 'onSurfaceVariant', + expandTrailingIconColor: 'onSurface', } as const satisfies Record; export const ListTokens = { ...sizes, ...colors }; diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 0adeb8c25d..30f396026c 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -189,7 +189,20 @@ describe('ListAccordion', () => { }); }); - it('drops to 12dp padding once the description wraps to a third line', async () => { + it('hits the container heights without measuring the description', async () => { + await render( + + + + ); + + expect(screen.getByTestId('list-accordion')).toHaveStyle({ + minHeight: 56, + paddingVertical: 12, + }); + }); + + it('keeps the two line container height once a description is present', async () => { await render( { ); expect(screen.getByTestId('list-accordion')).toHaveStyle({ - paddingVertical: 14, + minHeight: 72, + paddingVertical: 12, }); await fireEvent( @@ -211,10 +225,25 @@ describe('ListAccordion', () => { ); expect(screen.getByTestId('list-accordion')).toHaveStyle({ + minHeight: 72, paddingVertical: 12, }); }); + it('uses the expand token for the chevron', async () => { + await render( + + + + ); + + expect( + screen.getByText('chevron-down', { includeHiddenElements: true }) + ).toHaveStyle({ + color: getTheme().colors.onSurface, + }); + }); + it('applies the theme override to title and description typography', async () => { await render( { expect(toJSON()).toMatchSnapshot(); }); -it('drops to 12dp padding once the description wraps to a third line', async () => { +it('hits the one line container height without measuring the description', async () => { + await render(); + + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 56, + paddingVertical: 12, + }); +}); + +it('hits the two and three line container heights without measuring', async () => { await render( ); - expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 14 }); + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 72, + paddingVertical: 12, + }); await fireEvent(screen.getByText('Item description'), 'textLayout', { nativeEvent: { lines: [{}, {}] }, }); - expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 12 }); + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 72, + paddingVertical: 12, + }); +}); + +it('top aligns the accessories once the description wraps', async () => { + await render( + } + testID={testID} + /> + ); + + expect(screen.getByTestId('left-accessory')).toHaveStyle({ + alignSelf: 'center', + }); + + await fireEvent(screen.getByText('Item description'), 'textLayout', { + nativeEvent: { lines: [{}, {}] }, + }); + + expect(screen.getByTestId('left-accessory')).toHaveStyle({ + alignSelf: 'flex-start', + }); }); it('applies the theme override to title and description typography', async () => { diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 460faf181d..00c263e0b3 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -47,10 +47,12 @@ exports[`renders expanded accordion 1`] = ` }, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -131,7 +133,7 @@ exports[`renders expanded accordion 1`] = ` style={ [ { - "color": "rgba(73, 69, 79, 1)", + "color": "rgba(29, 27, 32, 1)", "fontSize": 24, }, [ @@ -163,10 +165,12 @@ exports[`renders expanded accordion 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -284,10 +288,12 @@ exports[`renders list accordion with children 1`] = ` }, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -415,7 +421,7 @@ exports[`renders list accordion with children 1`] = ` style={ [ { - "color": "rgba(73, 69, 79, 1)", + "color": "rgba(29, 27, 32, 1)", "fontSize": 24, }, [ @@ -490,10 +496,12 @@ exports[`renders list accordion with custom title and description styles 1`] = ` }, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -611,7 +619,7 @@ exports[`renders list accordion with custom title and description styles 1`] = ` style={ [ { - "color": "rgba(73, 69, 79, 1)", + "color": "rgba(29, 27, 32, 1)", "fontSize": 24, }, [ @@ -686,10 +694,12 @@ exports[`renders list accordion with left items 1`] = ` }, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -817,7 +827,7 @@ exports[`renders list accordion with left items 1`] = ` style={ [ { - "color": "rgba(73, 69, 79, 1)", + "color": "rgba(29, 27, 32, 1)", "fontSize": 24, }, [ @@ -892,10 +902,12 @@ exports[`renders multiline list accordion 1`] = ` }, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -1009,7 +1021,7 @@ exports[`renders multiline list accordion 1`] = ` style={ [ { - "color": "rgba(73, 69, 79, 1)", + "color": "rgba(29, 27, 32, 1)", "fontSize": 24, }, [ diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap index f0939d9d7a..3983303a17 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap @@ -122,10 +122,12 @@ exports[`renders list item with custom description 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -485,10 +487,12 @@ exports[`renders list item with custom title and description styles 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -604,10 +608,12 @@ exports[`renders list item with left and right items 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -768,10 +774,12 @@ exports[`renders list item with left item 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -897,10 +905,12 @@ exports[`renders list item with right item 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -982,10 +992,12 @@ exports[`renders list item with title and description 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], @@ -1097,10 +1109,12 @@ exports[`renders with a description with typeof number 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 14, + "minHeight": 72, }, undefined, ], diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap index 60b77c96a7..a7facb034c 100644 --- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap @@ -460,10 +460,12 @@ exports[`renders list section with custom title style 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -586,10 +588,12 @@ exports[`renders list section with custom title style 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -1166,10 +1170,12 @@ exports[`renders list section with subheader 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -1292,10 +1298,12 @@ exports[`renders list section with subheader 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -1832,10 +1840,12 @@ exports[`renders list section without subheader 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], @@ -1958,10 +1968,12 @@ exports[`renders list section without subheader 1`] = ` false, [ { + "justifyContent": "center", "paddingRight": 16, + "paddingVertical": 12, }, { - "paddingVertical": 16, + "minHeight": 56, }, undefined, ], From ca443923e4c3e8984d8d9d10640493996e2c6d74 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 28 Aug 2026 18:52:28 +0200 Subject: [PATCH 05/16] refactor: restore the List.Accordion colors helper --- src/components/List/ListAccordion.tsx | 5 ++--- src/components/List/utils.ts | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 4bf688ecb5..76c07b63c3 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -15,7 +15,7 @@ import { ListAccordionContext } from './ListAccordionContext'; import { ListAccordionGroupContext } from './ListAccordionGroup'; import { ListTokens } from './tokens'; import type { ListChildProps, Style } from './utils'; -import { getLeftStyles } from './utils'; +import { getAccordionColors, getLeftStyles } from './utils'; import { useLocale } from '../../core/locale'; import { useInternalTheme } from '../../core/theming'; import type { ThemeProp } from '../../theme/types'; @@ -232,8 +232,7 @@ const ListAccordion = ({ ? groupContext.expandedId === id : expandedInternal; - const titleTextColor = theme.colors[ListTokens.headlineColor]; - const descriptionColor = theme.colors[ListTokens.supportingTextColor]; + const { descriptionColor, titleTextColor } = getAccordionColors({ theme }); const handlePress = groupContext && id !== undefined diff --git a/src/components/List/utils.ts b/src/components/List/utils.ts index 296acc4e4e..d9fff8fef8 100644 --- a/src/components/List/utils.ts +++ b/src/components/List/utils.ts @@ -1,7 +1,7 @@ import type { StyleProp, TextProps, ViewStyle } from 'react-native'; import { ListTokens } from './tokens'; -import type { ThemeProp } from '../../theme/types'; +import type { InternalTheme, ThemeProp } from '../../theme/types'; type Description = | React.ReactNode @@ -44,3 +44,8 @@ export const getLeftStyles = (alignToTop: boolean, description: Description) => export const getRightStyles = (alignToTop: boolean, description: Description) => getAccessoryStyles(alignToTop, description); + +export const getAccordionColors = ({ theme }: { theme: InternalTheme }) => ({ + titleTextColor: theme.colors[ListTokens.headlineColor], + descriptionColor: theme.colors[ListTokens.supportingTextColor], +}); From 162c2f5ca7a12ff3d7046c37a10716f7e51ca873 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Tue, 1 Sep 2026 15:40:30 +0200 Subject: [PATCH 06/16] fix: align List spacing and container heights with MD3 --- src/components/List/ListAccordion.tsx | 156 ++++++++++-------- src/components/List/ListImage.tsx | 13 +- src/components/List/ListItem.tsx | 84 ++++++---- src/components/List/tokens.ts | 3 +- src/components/List/utils.ts | 10 ++ .../__tests__/ListAccordion.test.tsx | 4 +- src/components/__tests__/ListImage.test.tsx | 10 ++ src/components/__tests__/ListItem.test.tsx | 102 +++++++++++- .../__snapshots__/ListAccordion.test.tsx.snap | 28 ++-- .../__snapshots__/ListItem.test.tsx.snap | 21 ++- .../__snapshots__/ListSection.test.tsx.snap | 18 +- 11 files changed, 313 insertions(+), 136 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 76c07b63c3..dabdd461b5 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -15,7 +15,7 @@ import { ListAccordionContext } from './ListAccordionContext'; import { ListAccordionGroupContext } from './ListAccordionGroup'; import { ListTokens } from './tokens'; import type { ListChildProps, Style } from './utils'; -import { getAccordionColors, getLeftStyles } from './utils'; +import { ListRowContext, getAccordionColors, getLeftStyles } from './utils'; import { useLocale } from '../../core/locale'; import { useInternalTheme } from '../../core/theming'; import type { ThemeProp } from '../../theme/types'; @@ -239,93 +239,102 @@ const ListAccordion = ({ ? () => groupContext.onAccordionPress(id) : handlePressAction; - const hasLeft = left != null; - const accordionContext = React.useMemo(() => ({ hasLeft }), [hasLeft]); + const rowContext = React.useMemo( + () => ({ + verticalPadding: isDescriptionMultiline + ? ListTokens.threeLineVerticalPadding + : ListTokens.verticalPadding, + }), + [isDescriptionMultiline] + ); return ( - - + - {left - ? left({ - color: theme.colors[ListTokens.leadingIconColor], - style: getLeftStyles(isDescriptionMultiline, description), - }) - : null} - - - {title} - - {description ? ( + + {left + ? left({ + color: theme.colors[ListTokens.leadingIconColor], + style: getLeftStyles(isDescriptionMultiline, description), + }) + : null} + - {description} + {title} - ) : null} - - - {right ? ( - right({ - isExpanded: isExpanded, - }) - ) : ( - - )} + {description ? ( + + {description} + + ) : null} + + + {right ? ( + right({ + isExpanded: isExpanded, + }) + ) : ( + + )} + - - + + {isExpanded ? ( @@ -351,6 +360,9 @@ const styles = StyleSheet.create({ containerTwoLine: { minHeight: ListTokens.twoLineContainerHeight, }, + containerThreeLine: { + paddingVertical: ListTokens.threeLineVerticalPadding, + }, row: { flexDirection: 'row', }, @@ -359,7 +371,7 @@ const styles = StyleSheet.create({ }, trailingItem: { alignSelf: 'center', - paddingLeft: 8, + paddingLeft: ListTokens.leadingSpace, }, content: { flex: 1, diff --git a/src/components/List/ListImage.tsx b/src/components/List/ListImage.tsx index 213d4254c7..73a2ba3692 100644 --- a/src/components/List/ListImage.tsx +++ b/src/components/List/ListImage.tsx @@ -1,6 +1,9 @@ +import * as React from 'react'; import { StyleSheet, Image } from 'react-native'; import type { StyleProp, ImageSourcePropType, ImageStyle } from 'react-native'; +import { ListTokens } from './tokens'; +import { ListRowContext } from './utils'; import type { ThemeProp } from '../../theme/types'; export type Props = { @@ -37,9 +40,17 @@ const ListImage = ({ variant = 'image', theme: _theme, }: Props) => { + const { verticalPadding } = React.useContext(ListRowContext); + const getStyles = () => { if (variant === 'video') { - return [style, styles.video]; + return [ + style, + styles.video, + { + marginVertical: ListTokens.threeLineVerticalPadding - verticalPadding, + }, + ]; } return [style, styles.image]; diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 7ca2967e27..03ce165541 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -11,7 +11,7 @@ import type { } from 'react-native'; import { ListTokens } from './tokens'; -import { getLeftStyles, getRightStyles } from './utils'; +import { ListRowContext, getLeftStyles, getRightStyles } from './utils'; import type { Style } from './utils'; import { useInternalTheme } from '../../core/theming'; import type { ThemeProp } from '../../theme/types'; @@ -228,43 +228,56 @@ const ListItem = ({ const descriptionColor = theme.colors[ListTokens.supportingTextColor]; + const rowContext = React.useMemo( + () => ({ + verticalPadding: isDescriptionMultiline + ? ListTokens.threeLineVerticalPadding + : ListTokens.verticalPadding, + }), + [isDescriptionMultiline] + ); + return ( - - - {left - ? left({ - color: theme.colors[ListTokens.leadingIconColor], - style: getLeftStyles(isDescriptionMultiline, description), - }) - : null} - - {renderTitle()} + + + + {left + ? left({ + color: theme.colors[ListTokens.leadingIconColor], + style: getLeftStyles(isDescriptionMultiline, description), + }) + : null} + + {renderTitle()} - {description - ? renderDescription(descriptionColor, description) + {description + ? renderDescription(descriptionColor, description) + : null} + + {right + ? right({ + color: theme.colors[ListTokens.trailingIconColor], + style: getRightStyles(isDescriptionMultiline, description), + }) : null} - {right - ? right({ - color: theme.colors[ListTokens.trailingIconColor], - style: getRightStyles(isDescriptionMultiline, description), - }) - : null} - - + + ); }; @@ -282,6 +295,9 @@ const styles = StyleSheet.create({ containerTwoLine: { minHeight: ListTokens.twoLineContainerHeight, }, + containerThreeLine: { + paddingVertical: ListTokens.threeLineVerticalPadding, + }, row: { width: '100%', flexDirection: 'row', diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts index e67a604812..5df93882ed 100644 --- a/src/components/List/tokens.ts +++ b/src/components/List/tokens.ts @@ -1,7 +1,8 @@ import type { ColorRole } from '../../theme/types'; const sizes = { - verticalPadding: 12, + verticalPadding: 8, + threeLineVerticalPadding: 12, oneLineContainerHeight: 56, twoLineContainerHeight: 72, leadingSpace: 16, diff --git a/src/components/List/utils.ts b/src/components/List/utils.ts index d9fff8fef8..a0c5f1ef00 100644 --- a/src/components/List/utils.ts +++ b/src/components/List/utils.ts @@ -1,3 +1,4 @@ +import * as React from 'react'; import type { StyleProp, TextProps, ViewStyle } from 'react-native'; import { ListTokens } from './tokens'; @@ -45,6 +46,15 @@ export const getLeftStyles = (alignToTop: boolean, description: Description) => export const getRightStyles = (alignToTop: boolean, description: Description) => getAccessoryStyles(alignToTop, description); +/** + * Rows change their vertical padding with the number of lines, so a leading + * element taller than the default slot needs to know how much of the MD3 + * height the row already covers. + */ +export const ListRowContext = React.createContext<{ verticalPadding: number }>({ + verticalPadding: ListTokens.verticalPadding, +}); + export const getAccordionColors = ({ theme }: { theme: InternalTheme }) => ({ titleTextColor: theme.colors[ListTokens.headlineColor], descriptionColor: theme.colors[ListTokens.supportingTextColor], diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 30f396026c..019eb142d3 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -198,7 +198,7 @@ describe('ListAccordion', () => { expect(screen.getByTestId('list-accordion')).toHaveStyle({ minHeight: 56, - paddingVertical: 12, + paddingVertical: 8, }); }); @@ -215,7 +215,7 @@ describe('ListAccordion', () => { expect(screen.getByTestId('list-accordion')).toHaveStyle({ minHeight: 72, - paddingVertical: 12, + paddingVertical: 8, }); await fireEvent( diff --git a/src/components/__tests__/ListImage.test.tsx b/src/components/__tests__/ListImage.test.tsx index 04796fd73a..39fc779755 100644 --- a/src/components/__tests__/ListImage.test.tsx +++ b/src/components/__tests__/ListImage.test.tsx @@ -6,6 +6,16 @@ import { render } from '../../test-utils'; import ListImage from '../List/ListImage'; const styles = StyleSheet.create({ + image: { + width: 56, + height: 56, + }, + video: { + width: 114, + height: 64, + marginLeft: 0, + marginVertical: 4, + }, container: { width: 30, height: 56, diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 473b1a832b..555fb7c6f5 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -10,6 +10,7 @@ import { red500 } from '../../theme/colors'; import Chip from '../Chip/Chip'; import IconButton from '../IconButton/IconButton'; import ListIcon from '../List/ListIcon'; +import ListImage from '../List/ListImage'; import ListItem from '../List/ListItem'; const styles = StyleSheet.create({ @@ -22,6 +23,14 @@ const styles = StyleSheet.create({ content: { paddingLeft: 0, }, + avatar: { + width: 40, + height: 40, + }, + image: { + width: 56, + height: 56, + }, }); const testID = 'list-item'; @@ -183,7 +192,7 @@ it('hits the one line container height without measuring the description', async expect(screen.getByTestId(testID)).toHaveStyle({ minHeight: 56, - paddingVertical: 12, + paddingVertical: 8, }); }); @@ -198,7 +207,7 @@ it('hits the two and three line container heights without measuring', async () = expect(screen.getByTestId(testID)).toHaveStyle({ minHeight: 72, - paddingVertical: 12, + paddingVertical: 8, }); await fireEvent(screen.getByText('Item description'), 'textLayout', { @@ -211,6 +220,95 @@ it('hits the two and three line container heights without measuring', async () = }); }); +it('leaves a 40dp leading element on the one line container height', async () => { + await render( + ( + + )} + testID={testID} + /> + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 56, + paddingVertical: 8, + }); + expect(screen.getByTestId('left-accessory')).toHaveStyle({ height: 40 }); +}); + +it('leaves a 56dp leading image on the two line container height', async () => { + await render( + ( + + )} + testID={testID} + /> + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 72, + paddingVertical: 8, + }); + expect(screen.getByTestId('left-accessory')).toHaveStyle({ height: 56 }); +}); + +it('pads a 64dp leading video to the three line container height', async () => { + await render( + ( + + )} + testID={testID} + /> + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight: 56, + paddingVertical: 8, + }); + expect(screen.getByTestId('list-image')).toHaveStyle({ + height: 64, + marginVertical: 4, + }); +}); + +it('keeps a 64dp leading video on the same height once the description wraps', async () => { + await render( + ( + + )} + testID={testID} + /> + ); + + await fireEvent(screen.getByText('Item description'), 'textLayout', { + nativeEvent: { lines: [{}, {}] }, + }); + + expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 12 }); + expect(screen.getByTestId('list-image')).toHaveStyle({ + height: 64, + marginVertical: 0, + }); +}); + it('top aligns the accessories once the description wraps', async () => { await render( @@ -167,11 +168,12 @@ exports[`renders expanded accordion 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -290,11 +292,12 @@ exports[`renders list accordion with children 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -409,7 +412,7 @@ exports[`renders list accordion with children 1`] = ` style={ { "alignSelf": "center", - "paddingLeft": 8, + "paddingLeft": 16, } } > @@ -498,11 +501,12 @@ exports[`renders list accordion with custom title and description styles 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -607,7 +611,7 @@ exports[`renders list accordion with custom title and description styles 1`] = ` style={ { "alignSelf": "center", - "paddingLeft": 8, + "paddingLeft": 16, } } > @@ -696,11 +700,12 @@ exports[`renders list accordion with left items 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -815,7 +820,7 @@ exports[`renders list accordion with left items 1`] = ` style={ { "alignSelf": "center", - "paddingLeft": 8, + "paddingLeft": 16, } } > @@ -904,11 +909,12 @@ exports[`renders multiline list accordion 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -1009,7 +1015,7 @@ exports[`renders multiline list accordion 1`] = ` style={ { "alignSelf": "center", - "paddingLeft": 8, + "paddingLeft": 16, } } > diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap index 3983303a17..615b752e8c 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap @@ -124,11 +124,12 @@ exports[`renders list item with custom description 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -489,11 +490,12 @@ exports[`renders list item with custom title and description styles 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -610,11 +612,12 @@ exports[`renders list item with left and right items 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -776,11 +779,12 @@ exports[`renders list item with left item 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -907,11 +911,12 @@ exports[`renders list item with right item 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -994,11 +999,12 @@ exports[`renders list item with title and description 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] @@ -1111,11 +1117,12 @@ exports[`renders with a description with typeof number 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 72, }, + false, undefined, ], ] diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap index a7facb034c..2ef86d7255 100644 --- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap @@ -462,11 +462,12 @@ exports[`renders list section with custom title style 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -590,11 +591,12 @@ exports[`renders list section with custom title style 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -1172,11 +1174,12 @@ exports[`renders list section with subheader 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -1300,11 +1303,12 @@ exports[`renders list section with subheader 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -1842,11 +1846,12 @@ exports[`renders list section without subheader 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] @@ -1970,11 +1975,12 @@ exports[`renders list section without subheader 1`] = ` { "justifyContent": "center", "paddingRight": 16, - "paddingVertical": 12, + "paddingVertical": 8, }, { "minHeight": 56, }, + false, undefined, ], ] From c63d10c568f75d2de8f1478051ce258ccbc6f31a Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Tue, 1 Sep 2026 15:40:43 +0200 Subject: [PATCH 07/16] chore: forward accessory styles in the List.Item example --- example/src/Examples/ListItemExample.tsx | 59 ++++++++++-------------- 1 file changed, 24 insertions(+), 35 deletions(-) diff --git a/example/src/Examples/ListItemExample.tsx b/example/src/Examples/ListItemExample.tsx index f91eb04081..1cf1252071 100644 --- a/example/src/Examples/ListItemExample.tsx +++ b/example/src/Examples/ListItemExample.tsx @@ -1,15 +1,7 @@ -import { View, StyleSheet } from 'react-native'; - import { List, Divider, Checkbox, Avatar, Switch } from 'react-native-paper'; import ScreenWrapper from '../ScreenWrapper'; -const CenteredCheckbox = () => ( - - - -); - const ListItemExample = () => { return ( @@ -21,16 +13,19 @@ const ListItemExample = () => { description="Supporting text that is long enough to fill up multiple lines in the item" /> - } /> + } + /> } + right={(props) => } /> } + right={(props) => } /> @@ -54,19 +49,19 @@ const ListItemExample = () => { } - right={() => } + right={(props) => } /> } - right={() => } + right={(props) => } /> } - right={() => } + right={(props) => } /> @@ -98,7 +93,7 @@ const ListItemExample = () => { left={(props) => ( )} - right={() => } + right={(props) => } /> { left={(props) => ( )} - right={() => } + right={(props) => } /> { left={(props) => ( )} - right={() => } + right={(props) => } /> @@ -158,7 +153,7 @@ const ListItemExample = () => { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> @@ -228,7 +223,7 @@ const ListItemExample = () => { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={() => } + right={(props) => } /> @@ -260,35 +255,35 @@ const ListItemExample = () => { } + right={(props) => } /> } + right={(props) => } /> } + right={(props) => } /> } - right={() => } + right={(props) => } /> } - right={() => } + right={(props) => } /> } - right={() => } + right={(props) => } /> @@ -296,12 +291,6 @@ const ListItemExample = () => { ); }; -const styles = StyleSheet.create({ - centered: { - alignSelf: 'center', - }, -}); - ListItemExample.title = 'List.Item'; export default ListItemExample; From 7439898cbfd06cca78e58c1c89f50cc707eb7477 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 7 Aug 2026 12:29:52 +0200 Subject: [PATCH 08/16] feat: add selected state to List.Item and List.Accordion --- example/src/Examples/ListItemExample.tsx | 24 ++++++++++++ src/components/List/ListAccordion.tsx | 23 +++++++++-- src/components/List/ListItem.tsx | 28 ++++++++++--- src/components/List/tokens.ts | 2 + src/components/List/utils.ts | 28 +++++++++++-- .../__tests__/ListAccordion.test.tsx | 15 +++++++ src/components/__tests__/ListItem.test.tsx | 39 +++++++++++++++++++ .../__snapshots__/ListAccordion.test.tsx.snap | 3 ++ .../__snapshots__/ListItem.test.tsx.snap | 21 ++++++++++ .../__snapshots__/ListSection.test.tsx.snap | 18 +++++++++ 10 files changed, 188 insertions(+), 13 deletions(-) diff --git a/example/src/Examples/ListItemExample.tsx b/example/src/Examples/ListItemExample.tsx index 1cf1252071..923c3f7c53 100644 --- a/example/src/Examples/ListItemExample.tsx +++ b/example/src/Examples/ListItemExample.tsx @@ -1,10 +1,34 @@ +import { useState } from 'react'; + import { List, Divider, Checkbox, Avatar, Switch } from 'react-native-paper'; import ScreenWrapper from '../ScreenWrapper'; +const SelectableSection = () => { + const [selected, setSelected] = useState(0); + + return ( + + {[0, 1, 2].map((index) => ( + setSelected(index)} + left={(props) => } + /> + ))} + + + ); +}; + const ListItemExample = () => { return ( + + diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index dabdd461b5..adbb1d42d1 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -47,6 +47,10 @@ export type Props = { * You'll need to update this prop when you want to toggle the component or on `onPress`. */ expanded?: boolean; + /** + * Whether to highlight the accordion as selected. + */ + selected?: boolean; /** * Function to execute on press. */ @@ -191,6 +195,7 @@ const ListAccordion = ({ onLongPress, delayLongPress, expanded: expandedProp, + selected, 'aria-label': ariaLabel, pointerEvents = 'none', titleMaxFontSizeMultiplier, @@ -232,7 +237,12 @@ const ListAccordion = ({ ? groupContext.expandedId === id : expandedInternal; - const { descriptionColor, titleTextColor } = getAccordionColors({ theme }); + const { + descriptionColor, + titleTextColor, + leadingIconColor, + trailingIconColor, + } = getAccordionColors({ theme, selected }); const handlePress = groupContext && id !== undefined @@ -251,7 +261,11 @@ const ListAccordion = ({ return ( {left ? left({ - color: theme.colors[ListTokens.leadingIconColor], + color: leadingIconColor, style: getLeftStyles(isDescriptionMultiline, description), }) : null} @@ -326,7 +341,7 @@ const ListAccordion = ({ ) : ( diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 03ce165541..1d1843c189 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -57,6 +57,10 @@ export type Props = Omit< * Callback which returns a React element to display on the right side. */ right?: (props: { color: ColorValue; style?: Style }) => React.ReactNode; + /** + * Whether to highlight the list item as selected. + */ + selected?: boolean; /** * Function to execute on press. */ @@ -148,6 +152,7 @@ const ListItem = ({ right, title, description, + selected, onPress, theme: themeOverrides, style, @@ -174,6 +179,13 @@ const ListItem = ({ setIsDescriptionMultiline(nativeEvent.lines.length >= 2); }; + const backgroundColor = selected + ? theme.colors[ListTokens.selectedContainerColor] + : undefined; + const titleColor = selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.headlineColor]; + const renderDescription = ( descriptionColor: ColorValue, description?: Description | null @@ -202,8 +214,6 @@ const ListItem = ({ }; const renderTitle = () => { - const titleColor = theme.colors[ListTokens.headlineColor]; - return typeof title === 'function' ? ( title({ selectable: false, @@ -226,7 +236,9 @@ const ListItem = ({ ); }; - const descriptionColor = theme.colors[ListTokens.supportingTextColor]; + const descriptionColor = selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.supportingTextColor]; const rowContext = React.useMemo( () => ({ @@ -246,16 +258,20 @@ const ListItem = ({ styles.container, description ? styles.containerTwoLine : styles.containerOneLine, isDescriptionMultiline && styles.containerThreeLine, + { backgroundColor }, style, ]} onPress={onPress} + aria-selected={selected} theme={theme} testID={testID} > {left ? left({ - color: theme.colors[ListTokens.leadingIconColor], + color: selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.leadingIconColor], style: getLeftStyles(isDescriptionMultiline, description), }) : null} @@ -271,7 +287,9 @@ const ListItem = ({ {right ? right({ - color: theme.colors[ListTokens.trailingIconColor], + color: selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.trailingIconColor], style: getRightStyles(isDescriptionMultiline, description), }) : null} diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts index 5df93882ed..f1fd872458 100644 --- a/src/components/List/tokens.ts +++ b/src/components/List/tokens.ts @@ -16,6 +16,8 @@ const colors = { leadingIconColor: 'onSurfaceVariant', trailingIconColor: 'onSurfaceVariant', expandTrailingIconColor: 'onSurface', + selectedContainerColor: 'primaryContainer', + selectedContentColor: 'onPrimaryContainer', } as const satisfies Record; export const ListTokens = { ...sizes, ...colors }; diff --git a/src/components/List/utils.ts b/src/components/List/utils.ts index a0c5f1ef00..1d9a9cc1ff 100644 --- a/src/components/List/utils.ts +++ b/src/components/List/utils.ts @@ -55,7 +55,27 @@ export const ListRowContext = React.createContext<{ verticalPadding: number }>({ verticalPadding: ListTokens.verticalPadding, }); -export const getAccordionColors = ({ theme }: { theme: InternalTheme }) => ({ - titleTextColor: theme.colors[ListTokens.headlineColor], - descriptionColor: theme.colors[ListTokens.supportingTextColor], -}); +export const getAccordionColors = ({ + theme, + selected, +}: { + theme: InternalTheme; + selected?: boolean; +}) => { + const selectedContentColor = theme.colors[ListTokens.selectedContentColor]; + + return { + titleTextColor: selected + ? selectedContentColor + : theme.colors[ListTokens.headlineColor], + descriptionColor: selected + ? selectedContentColor + : theme.colors[ListTokens.supportingTextColor], + leadingIconColor: selected + ? selectedContentColor + : theme.colors[ListTokens.leadingIconColor], + trailingIconColor: selected + ? selectedContentColor + : theme.colors[ListTokens.expandTrailingIconColor], + }; +}; diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index 019eb142d3..d9891a124a 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -262,4 +262,19 @@ describe('ListAccordion', () => { fontSize: 77, }); }); + + it('renders a selected accordion on the primary container', async () => { + await render( + + + + ); + + expect(screen.getByText('Accordion item 1')).toHaveStyle({ + color: getTheme().colors.onPrimaryContainer, + }); + expect(screen.getByText('Supporting')).toHaveStyle({ + color: getTheme().colors.onPrimaryContainer, + }); + }); }); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 555fb7c6f5..432049108a 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -5,6 +5,7 @@ import { Text, View } from 'react-native'; import { expect, it, jest } from '@jest/globals'; import { userEvent } from '@testing-library/react-native'; +import { getTheme } from '../../core/theming'; import { fireEvent, render, screen } from '../../test-utils'; import { red500 } from '../../theme/colors'; import Chip from '../Chip/Chip'; @@ -347,3 +348,41 @@ it('applies the theme override to title and description typography', async () => expect(screen.getByText('First Item')).toHaveStyle({ fontSize: 99 }); expect(screen.getByText('Item description')).toHaveStyle({ fontSize: 77 }); }); + +it('renders an unselected list item on surface colors', async () => { + await render( + + ); + + expect(screen.getByText('First Item')).toHaveStyle({ + color: getTheme().colors.onSurface, + }); + expect(screen.getByText('Item description')).toHaveStyle({ + color: getTheme().colors.onSurfaceVariant, + }); +}); + +it('renders a selected list item on the primary container', async () => { + await render( + + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ + backgroundColor: getTheme().colors.primaryContainer, + }); + expect(screen.getByText('First Item')).toHaveStyle({ + color: getTheme().colors.onPrimaryContainer, + }); + expect(screen.getByText('Item description')).toHaveStyle({ + color: getTheme().colors.onPrimaryContainer, + }); +}); diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 3ed6f9ca2a..712d5b6fea 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -174,6 +174,9 @@ exports[`renders expanded accordion 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap index 615b752e8c..1b7f914bec 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap @@ -130,6 +130,9 @@ exports[`renders list item with custom description 1`] = ` "minHeight": 72, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -496,6 +499,9 @@ exports[`renders list item with custom title and description styles 1`] = ` "minHeight": 72, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -618,6 +624,9 @@ exports[`renders list item with left and right items 1`] = ` "minHeight": 72, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -785,6 +794,9 @@ exports[`renders list item with left item 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -917,6 +929,9 @@ exports[`renders list item with right item 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1005,6 +1020,9 @@ exports[`renders list item with title and description 1`] = ` "minHeight": 72, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1123,6 +1141,9 @@ exports[`renders with a description with typeof number 1`] = ` "minHeight": 72, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap index 2ef86d7255..91aee138d2 100644 --- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap @@ -468,6 +468,9 @@ exports[`renders list section with custom title style 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -597,6 +600,9 @@ exports[`renders list section with custom title style 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1180,6 +1186,9 @@ exports[`renders list section with subheader 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1309,6 +1318,9 @@ exports[`renders list section with subheader 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1852,6 +1864,9 @@ exports[`renders list section without subheader 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -1981,6 +1996,9 @@ exports[`renders list section without subheader 1`] = ` "minHeight": 56, }, false, + { + "backgroundColor": undefined, + }, undefined, ], ] From a3e1bf179bfd5e62e79077b5ab8cea790daffe6e Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 7 Aug 2026 12:33:36 +0200 Subject: [PATCH 09/16] feat: animate List.Accordion expand and collapse --- src/components/List/ListAccordion.tsx | 114 ++++- .../__snapshots__/ListAccordion.test.tsx.snap | 430 +++++++++++------- 2 files changed, 377 insertions(+), 167 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index adbb1d42d1..2969833252 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -11,13 +11,25 @@ import type { ViewStyle, } from 'react-native'; -import { ListAccordionContext } from './ListAccordionContext'; +import Animated, { + Easing, + ReduceMotion, + useAnimatedStyle, + useSharedValue, + withTiming, +} from 'react-native-reanimated'; +import type { + EntryAnimationsValues, + ExitAnimationsValues, +} from 'react-native-reanimated'; + import { ListAccordionGroupContext } from './ListAccordionGroup'; import { ListTokens } from './tokens'; import type { ListChildProps, Style } from './utils'; import { ListRowContext, getAccordionColors, getLeftStyles } from './utils'; import { useLocale } from '../../core/locale'; import { useInternalTheme } from '../../core/theming'; +import { useReduceMotion } from '../../theme/accessibility/ReduceMotionContext'; import type { ThemeProp } from '../../theme/types'; import MaterialCommunityIcon from '../MaterialCommunityIcon'; import TouchableRipple from '../TouchableRipple/TouchableRipple'; @@ -237,6 +249,62 @@ const ListAccordion = ({ ? groupContext.expandedId === id : expandedInternal; + const reduceMotion = useReduceMotion(); + const reanimatedReduceMotion = reduceMotion + ? ReduceMotion.Always + : ReduceMotion.Never; + + const timingConfig = React.useMemo( + () => ({ + duration: theme.motion.duration.medium2, + easing: Easing.bezier(...theme.motion.easing.emphasized), + reduceMotion: reanimatedReduceMotion, + }), + [ + theme.motion.duration.medium2, + theme.motion.easing.emphasized, + reanimatedReduceMotion, + ] + ); + + const chevronProgress = useSharedValue(isExpanded ? 1 : 0); + + React.useEffect(() => { + chevronProgress.value = withTiming(isExpanded ? 1 : 0, timingConfig); + }, [isExpanded, chevronProgress, timingConfig]); + + const chevronStyle = useAnimatedStyle(() => ({ + transform: [{ rotate: `${chevronProgress.value * 180}deg` }], + })); + + const expandAnimation = React.useCallback( + (values: EntryAnimationsValues) => { + 'worklet'; + return { + initialValues: { height: 0, opacity: 0 }, + animations: { + height: withTiming(values.targetHeight, timingConfig), + opacity: withTiming(1, timingConfig), + }, + }; + }, + [timingConfig] + ); + + const collapseAnimation = React.useCallback( + (values: ExitAnimationsValues) => { + 'worklet'; + return { + initialValues: { height: values.currentHeight, opacity: 1 }, + animations: { + height: withTiming(0, timingConfig), + opacity: withTiming(0, timingConfig), + }, + }; + }, + [timingConfig] + ); + const { descriptionColor, titleTextColor, @@ -339,12 +407,14 @@ const ListAccordion = ({ isExpanded: isExpanded, }) ) : ( - + + + )} @@ -353,9 +423,27 @@ const ListAccordion = ({ {isExpanded ? ( - - {children} - + + {React.Children.map(children, (child) => { + if ( + left && + React.isValidElement(child) && + !child.props.left && + !child.props.right + ) { + return React.cloneElement(child, { + style: [styles.child, child.props.style], + theme, + }); + } + + return child; + })} + ) : null} ); @@ -388,6 +476,12 @@ const styles = StyleSheet.create({ alignSelf: 'center', paddingLeft: ListTokens.leadingSpace, }, + child: { + paddingLeft: 40, + }, + expandedContent: { + overflow: 'hidden', + }, content: { flex: 1, justifyContent: 'center', diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 712d5b6fea..93e6f6398c 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -126,70 +126,114 @@ exports[`renders expanded accordion 1`] = ` } } > - - chevron-up - + + chevron-down + + @@ -197,49 +241,61 @@ exports[`renders expanded accordion 1`] = ` style={ [ { - "paddingLeft": 16, - }, - { - "flexGrow": 1, - "flexShrink": 1, - "justifyContent": "center", + "flexDirection": "row", + "width": "100%", }, undefined, ] } > - + - List item 1 - + ] + } + > + List item 1 + + @@ -419,35 +475,50 @@ exports[`renders list accordion with children 1`] = ` } } > - - chevron-down - + + chevron-down + + @@ -618,35 +689,50 @@ exports[`renders list accordion with custom title and description styles 1`] = ` } } > - - chevron-down - + + chevron-down + + @@ -827,35 +913,50 @@ exports[`renders list accordion with left items 1`] = ` } } > - - chevron-down - + + chevron-down + + @@ -1022,35 +1123,50 @@ exports[`renders multiline list accordion 1`] = ` } } > - - chevron-down - + + chevron-down + + From 9e6ce09794dac15c1b903d06f2ce058fc3176d51 Mon Sep 17 00:00:00 2001 From: Adam Sajko Date: Fri, 7 Aug 2026 13:23:41 +0200 Subject: [PATCH 10/16] feat: add typed leading and trailing slots to List.Item --- example/src/Examples/ListItemExample.tsx | 2 +- src/components/List/ListIcon.tsx | 6 +- src/components/List/ListItem.tsx | 90 +++++++++++++++------- src/components/List/ListItemContext.tsx | 10 +++ src/components/__tests__/ListItem.test.tsx | 44 +++++++++++ 5 files changed, 124 insertions(+), 28 deletions(-) create mode 100644 src/components/List/ListItemContext.tsx diff --git a/example/src/Examples/ListItemExample.tsx b/example/src/Examples/ListItemExample.tsx index 923c3f7c53..030d21cef8 100644 --- a/example/src/Examples/ListItemExample.tsx +++ b/example/src/Examples/ListItemExample.tsx @@ -16,7 +16,7 @@ const SelectableSection = () => { description="Supporting text" selected={index === selected} onPress={() => setSelected(index)} - left={(props) => } + leading={} /> ))} diff --git a/src/components/List/ListIcon.tsx b/src/components/List/ListIcon.tsx index ff02dea7f6..fb06e6463e 100644 --- a/src/components/List/ListIcon.tsx +++ b/src/components/List/ListIcon.tsx @@ -1,6 +1,8 @@ +import * as React from 'react'; import { StyleSheet, View } from 'react-native'; import type { ColorValue, StyleProp, ViewStyle } from 'react-native'; +import { ListItemContext } from './ListItemContext'; import { useInternalTheme } from '../../core/theming'; import type { ThemeProp } from '../../theme/types'; import Icon from '../Icon'; @@ -50,10 +52,12 @@ const ListIcon = ({ theme: themeOverrides, }: Props) => { const theme = useInternalTheme(themeOverrides); + const listItem = React.useContext(ListItemContext); + const color = iconColor ?? listItem?.color; return ( - + ); }; diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 1d1843c189..7d5b2b6b63 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -10,6 +10,7 @@ import type { ViewStyle, } from 'react-native'; +import { ListItemContext } from './ListItemContext'; import { ListTokens } from './tokens'; import { ListRowContext, getLeftStyles, getRightStyles } from './utils'; import type { Style } from './utils'; @@ -49,6 +50,14 @@ export type Props = Omit< * Description text for the list item or callback which returns a React element to display the description. */ description?: Description; + /** + * Element to display in the leading slot. Takes precedence over `left`. + */ + leading?: React.ReactNode; + /** + * Element to display in the trailing slot. Takes precedence over `right`. + */ + trailing?: React.ReactNode; /** * Callback which returns a React element to display on the left side. */ @@ -150,6 +159,8 @@ export type Props = Omit< const ListItem = ({ left, right, + leading, + trailing, title, description, selected, @@ -249,6 +260,45 @@ const ListItem = ({ [isDescriptionMultiline] ); + const accessoryContext = React.useMemo( + () => ({ color: descriptionColor }), + [descriptionColor] + ); + + const renderLeading = () => { + const accessoryStyle = getLeftStyles(isDescriptionMultiline, description); + + if (leading) { + return {leading}; + } + + return left + ? left({ + color: selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.leadingIconColor], + style: accessoryStyle, + }) + : null; + }; + + const renderTrailing = () => { + const accessoryStyle = getRightStyles(isDescriptionMultiline, description); + + if (trailing) { + return {trailing}; + } + + return right + ? right({ + color: selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.trailingIconColor], + style: accessoryStyle, + }) + : null; + }; + return ( - - {left - ? left({ - color: selected - ? theme.colors[ListTokens.selectedContentColor] - : theme.colors[ListTokens.leadingIconColor], - style: getLeftStyles(isDescriptionMultiline, description), - }) - : null} - - {renderTitle()} + + + {renderLeading()} + + {renderTitle()} - {description - ? renderDescription(descriptionColor, description) - : null} + {description + ? renderDescription(descriptionColor, description) + : null} + + {renderTrailing()} - {right - ? right({ - color: selected - ? theme.colors[ListTokens.selectedContentColor] - : theme.colors[ListTokens.trailingIconColor], - style: getRightStyles(isDescriptionMultiline, description), - }) - : null} - + ); diff --git a/src/components/List/ListItemContext.tsx b/src/components/List/ListItemContext.tsx new file mode 100644 index 0000000000..f372559a93 --- /dev/null +++ b/src/components/List/ListItemContext.tsx @@ -0,0 +1,10 @@ +import * as React from 'react'; +import type { ColorValue } from 'react-native'; + +export type ListItemContextType = { + color: ColorValue; +}; + +export const ListItemContext = React.createContext( + null +); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 432049108a..a3fb1f533e 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -310,6 +310,50 @@ it('keeps a 64dp leading video on the same height once the description wraps', a }); }); +it('colors a leading List.Icon from the list item context', async () => { + await render( + } + testID={testID} + /> + ); + + expect( + screen.getByText('folder', { includeHiddenElements: true }) + ).toHaveStyle({ color: getTheme().colors.onSurfaceVariant }); +}); + +it('renders the trailing slot', async () => { + await render( + Trailing} + testID={testID} + /> + ); + + expect(screen.getByText('Trailing')).toBeOnTheScreen(); +}); + +it('prefers the typed slots over the left and right render props', async () => { + await render( + Leading slot} + trailing={Trailing slot} + left={() => Left render prop} + right={() => Right render prop} + testID={testID} + /> + ); + + expect(screen.getByText('Leading slot')).toBeOnTheScreen(); + expect(screen.getByText('Trailing slot')).toBeOnTheScreen(); + expect(screen.queryByText('Left render prop')).not.toBeOnTheScreen(); + expect(screen.queryByText('Right render prop')).not.toBeOnTheScreen(); +}); + it('top aligns the accessories once the description wraps', async () => { await render( Date: Wed, 16 Sep 2026 17:08:01 +0200 Subject: [PATCH 11/16] fix: give the List.Item slots their own accessory color --- src/components/List/ListItem.tsx | 68 +++--- .../__tests__/ListAccordion.test.tsx | 19 +- src/components/__tests__/ListItem.test.tsx | 194 ++++++------------ 3 files changed, 107 insertions(+), 174 deletions(-) diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 7d5b2b6b63..31f5c79587 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -260,42 +260,49 @@ const ListItem = ({ [isDescriptionMultiline] ); - const accessoryContext = React.useMemo( - () => ({ color: descriptionColor }), - [descriptionColor] + const leadingColor = selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.leadingIconColor]; + const trailingColor = selected + ? theme.colors[ListTokens.selectedContentColor] + : theme.colors[ListTokens.trailingIconColor]; + + const leadingContext = React.useMemo( + () => ({ color: leadingColor }), + [leadingColor] + ); + const trailingContext = React.useMemo( + () => ({ color: trailingColor }), + [trailingColor] ); const renderLeading = () => { const accessoryStyle = getLeftStyles(isDescriptionMultiline, description); if (leading) { - return {leading}; + return ( + + {leading} + + ); } - return left - ? left({ - color: selected - ? theme.colors[ListTokens.selectedContentColor] - : theme.colors[ListTokens.leadingIconColor], - style: accessoryStyle, - }) - : null; + return left ? left({ color: leadingColor, style: accessoryStyle }) : null; }; const renderTrailing = () => { const accessoryStyle = getRightStyles(isDescriptionMultiline, description); if (trailing) { - return {trailing}; + return ( + + {trailing} + + ); } return right - ? right({ - color: selected - ? theme.colors[ListTokens.selectedContentColor] - : theme.colors[ListTokens.trailingIconColor], - style: accessoryStyle, - }) + ? right({ color: trailingColor, style: accessoryStyle }) : null; }; @@ -316,22 +323,17 @@ const ListItem = ({ theme={theme} testID={testID} > - - - {renderLeading()} - - {renderTitle()} + + {renderLeading()} + + {renderTitle()} - {description - ? renderDescription(descriptionColor, description) - : null} - - {renderTrailing()} + {description + ? renderDescription(descriptionColor, description) + : null} - + {renderTrailing()} + ); diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index d9891a124a..fe2697c38d 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -165,21 +165,12 @@ describe('ListAccordion', () => { ); }); - it('keeps the title on onSurface when collapsed', async () => { + it.each([ + ['collapsed', false], + ['expanded', true], + ])('keeps the title on onSurface when %s', async (_label, expanded) => { await render( - - - - ); - - expect(screen.getByText('Accordion item 1')).toHaveStyle({ - color: getTheme().colors.onSurface, - }); - }); - - it('keeps the title on onSurface when expanded', async () => { - await render( - + ); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index a3fb1f533e..290c58a5f9 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -11,7 +11,6 @@ import { red500 } from '../../theme/colors'; import Chip from '../Chip/Chip'; import IconButton from '../IconButton/IconButton'; import ListIcon from '../List/ListIcon'; -import ListImage from '../List/ListImage'; import ListItem from '../List/ListItem'; const styles = StyleSheet.create({ @@ -32,6 +31,10 @@ const styles = StyleSheet.create({ width: 56, height: 56, }, + video: { + width: 114, + height: 64, + }, }); const testID = 'list-item'; @@ -221,107 +224,47 @@ it('hits the two and three line container heights without measuring', async () = }); }); -it('leaves a 40dp leading element on the one line container height', async () => { - await render( - ( - - )} - testID={testID} - /> - ); - - expect(screen.getByTestId(testID)).toHaveStyle({ - minHeight: 56, - paddingVertical: 8, - }); - expect(screen.getByTestId('left-accessory')).toHaveStyle({ height: 40 }); -}); - -it('leaves a 56dp leading image on the two line container height', async () => { - await render( - ( - - )} - testID={testID} - /> - ); - - expect(screen.getByTestId(testID)).toHaveStyle({ - minHeight: 72, - paddingVertical: 8, - }); - expect(screen.getByTestId('left-accessory')).toHaveStyle({ height: 56 }); -}); - -it('pads a 64dp leading video to the three line container height', async () => { - await render( - ( - - )} - testID={testID} - /> - ); - - expect(screen.getByTestId(testID)).toHaveStyle({ - minHeight: 56, - paddingVertical: 8, - }); - expect(screen.getByTestId('list-image')).toHaveStyle({ - height: 64, - marginVertical: 4, - }); -}); - -it('keeps a 64dp leading video on the same height once the description wraps', async () => { - await render( - ( - - )} - testID={testID} - /> - ); - - await fireEvent(screen.getByText('Item description'), 'textLayout', { - nativeEvent: { lines: [{}, {}] }, - }); +it.each([ + ['a 40dp accessory', styles.avatar, undefined, 56], + ['a 56dp accessory', styles.image, 'Item description', 72], + ['a 64dp accessory', styles.video, undefined, 56], +])( + 'keeps the container height with %s in the leading slot', + async (_label, accessoryStyle, description, minHeight) => { + await render( + ( + + )} + testID={testID} + /> + ); - expect(screen.getByTestId(testID)).toHaveStyle({ paddingVertical: 12 }); - expect(screen.getByTestId('list-image')).toHaveStyle({ - height: 64, - marginVertical: 0, - }); -}); + expect(screen.getByTestId(testID)).toHaveStyle({ + minHeight, + paddingVertical: 8, + }); + } +); -it('colors a leading List.Icon from the list item context', async () => { +it('colors the typed slots from the list item context', async () => { await render( } + trailing={} testID={testID} /> ); expect( screen.getByText('folder', { includeHiddenElements: true }) - ).toHaveStyle({ color: getTheme().colors.onSurfaceVariant }); + ).toHaveStyle({ color: LightTheme.colors.onSurfaceVariant }); + expect( + screen.getByText('chevron-right', { includeHiddenElements: true }) + ).toHaveStyle({ color: LightTheme.colors.onSurfaceVariant }); }); it('renders the trailing slot', async () => { @@ -393,40 +336,37 @@ it('applies the theme override to title and description typography', async () => expect(screen.getByText('Item description')).toHaveStyle({ fontSize: 77 }); }); -it('renders an unselected list item on surface colors', async () => { - await render( - - ); - - expect(screen.getByText('First Item')).toHaveStyle({ - color: getTheme().colors.onSurface, - }); - expect(screen.getByText('Item description')).toHaveStyle({ - color: getTheme().colors.onSurfaceVariant, - }); -}); - -it('renders a selected list item on the primary container', async () => { - await render( - - ); - - expect(screen.getByTestId(testID)).toHaveStyle({ - backgroundColor: getTheme().colors.primaryContainer, - }); - expect(screen.getByText('First Item')).toHaveStyle({ - color: getTheme().colors.onPrimaryContainer, - }); - expect(screen.getByText('Item description')).toHaveStyle({ - color: getTheme().colors.onPrimaryContainer, - }); -}); +it.each([ + [ + 'an unselected item on surface colors', + false, + undefined, + LightTheme.colors.onSurface, + LightTheme.colors.onSurfaceVariant, + ], + [ + 'a selected item on the primary container', + true, + LightTheme.colors.primaryContainer, + LightTheme.colors.onPrimaryContainer, + LightTheme.colors.onPrimaryContainer, + ], +])( + 'renders %s', + async (_label, selected, backgroundColor, titleColor, descriptionColor) => { + await render( + + ); + + expect(screen.getByTestId(testID)).toHaveStyle({ backgroundColor }); + expect(screen.getByText('First Item')).toHaveStyle({ color: titleColor }); + expect(screen.getByText('Item description')).toHaveStyle({ + color: descriptionColor, + }); + } +); From c41f29e0c916e53fd068332f38d51a53c77cec5b Mon Sep 17 00:00:00 2001 From: Roksana Zawilowska Date: Wed, 21 Oct 2026 15:17:29 +0200 Subject: [PATCH 12/16] docs(example): add selected accordion to List.Accordion example --- example/src/Examples/ListAccordionExample.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/example/src/Examples/ListAccordionExample.tsx b/example/src/Examples/ListAccordionExample.tsx index 58c3841de5..4dcf66a44f 100644 --- a/example/src/Examples/ListAccordionExample.tsx +++ b/example/src/Examples/ListAccordionExample.tsx @@ -29,6 +29,13 @@ const ListAccordionExample = () => { > + } + title="Selected" + selected + > + + From aaa0867c3a0cbe920cd22d906452fbc40ce26199 Mon Sep 17 00:00:00 2001 From: Jacek Paciorek Date: Thu, 12 Nov 2026 11:02:51 +0100 Subject: [PATCH 13/16] fix(list): move rows below the accordion with its content --- src/components/List/ListAccordion.tsx | 146 +++++++++------ src/components/List/ListItem.tsx | 2 + .../__tests__/ListAccordion.test.tsx | 51 +++++- .../__snapshots__/ListAccordion.test.tsx.snap | 170 +++++++++--------- 4 files changed, 229 insertions(+), 140 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 2969833252..987fa227b9 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -3,6 +3,8 @@ import { StyleSheet, View } from 'react-native'; import type { ColorValue, GestureResponderEvent, + LayoutChangeEvent, + NativeSyntheticEvent, PressableAndroidRippleConfig, StyleProp, TextLayoutEvent, @@ -14,14 +16,13 @@ import type { import Animated, { Easing, ReduceMotion, + cubicBezier, useAnimatedStyle, useSharedValue, withTiming, + type CSSStyle, } from 'react-native-reanimated'; -import type { - EntryAnimationsValues, - ExitAnimationsValues, -} from 'react-native-reanimated'; +import { scheduleOnRN } from 'react-native-worklets'; import { ListAccordionGroupContext } from './ListAccordionGroup'; import { ListTokens } from './tokens'; @@ -36,6 +37,8 @@ import TouchableRipple from '../TouchableRipple/TouchableRipple'; import type { Props as TouchableRippleProps } from '../TouchableRipple/TouchableRipple'; import Text from '../Typography/Text'; +type ContentPhase = 'collapsed' | 'expanding' | 'expanded' | 'collapsing'; + export type Props = { /** * Title text for the list accordion. @@ -267,43 +270,77 @@ const ListAccordion = ({ ] ); - const chevronProgress = useSharedValue(isExpanded ? 1 : 0); + const chevronStyle: CSSStyle = { + transform: [{ rotate: isExpanded ? '180deg' : '0deg' }], + transitionProperty: ['transform'], + transitionDuration: reduceMotion ? 0 : theme.motion.duration.medium2, + transitionTimingFunction: cubicBezier(...theme.motion.easing.emphasized), + }; + + const [contentPhase, setContentPhase] = React.useState( + isExpanded ? 'expanded' : 'collapsed' + ); + const [contentHeight, setContentHeight] = React.useState(0); + + // Start the transition in the render where `isExpanded` changes, so the + // content is mounted and measured before the first animation frame. + if ( + isExpanded && + (contentPhase === 'collapsed' || contentPhase === 'collapsing') + ) { + setContentPhase('expanding'); + } else if ( + !isExpanded && + (contentPhase === 'expanded' || contentPhase === 'expanding') + ) { + setContentPhase('collapsing'); + } + + const contentProgress = useSharedValue(isExpanded ? 1 : 0); React.useEffect(() => { - chevronProgress.value = withTiming(isExpanded ? 1 : 0, timingConfig); - }, [isExpanded, chevronProgress, timingConfig]); + // An interrupted animation reports `finished: false`, and a stale one + // cannot move the phase because the phase no longer matches. + const finishTransition = (finished: boolean) => { + if (!finished) { + return; + } - const chevronStyle = useAnimatedStyle(() => ({ - transform: [{ rotate: `${chevronProgress.value * 180}deg` }], - })); + setContentPhase((phase) => { + if (isExpanded && phase === 'expanding') { + return 'expanded'; + } - const expandAnimation = React.useCallback( - (values: EntryAnimationsValues) => { - 'worklet'; - return { - initialValues: { height: 0, opacity: 0 }, - animations: { - height: withTiming(values.targetHeight, timingConfig), - opacity: withTiming(1, timingConfig), - }, - }; - }, - [timingConfig] - ); + if (!isExpanded && phase === 'collapsing') { + return 'collapsed'; + } - const collapseAnimation = React.useCallback( - (values: ExitAnimationsValues) => { - 'worklet'; - return { - initialValues: { height: values.currentHeight, opacity: 1 }, - animations: { - height: withTiming(0, timingConfig), - opacity: withTiming(0, timingConfig), - }, - }; - }, - [timingConfig] - ); + return phase; + }); + }; + + contentProgress.value = withTiming( + isExpanded ? 1 : 0, + timingConfig, + (finished) => scheduleOnRN(finishTransition, finished ?? false) + ); + }, [isExpanded, contentProgress, timingConfig]); + + // The wrapper height changes in layout, so the rows below the accordion + // move with it. When the transition ends, the height goes back to `auto` + // so that content which changes size (for example, a nested accordion) + // is not clipped. + const contentTransitionStyle = useAnimatedStyle(() => ({ + height: + contentPhase === 'expanded' + ? 'auto' + : contentProgress.value * contentHeight, + opacity: contentProgress.value, + })); + + const onContentLayout = (event: LayoutChangeEvent) => { + setContentHeight(event.nativeEvent.layout.height); + }; const { descriptionColor, @@ -422,27 +459,18 @@ const ListAccordion = ({ - {isExpanded ? ( - - {React.Children.map(children, (child) => { - if ( - left && - React.isValidElement(child) && - !child.props.left && - !child.props.right - ) { - return React.cloneElement(child, { - style: [styles.child, child.props.style], - theme, - }); + {contentPhase !== 'collapsed' ? ( + + + + {children} + + ) : null} @@ -482,6 +510,12 @@ const styles = StyleSheet.create({ expandedContent: { overflow: 'hidden', }, + transitioningContent: { + position: 'absolute', + top: 0, + left: 0, + right: 0, + }, content: { flex: 1, justifyContent: 'center', diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx index 31f5c79587..8c93b3c1ae 100644 --- a/src/components/List/ListItem.tsx +++ b/src/components/List/ListItem.tsx @@ -182,6 +182,8 @@ const ListItem = ({ ...rest }: Props) => { const theme = useInternalTheme(themeOverrides); + const { hasLeft } = React.useContext(ListAccordionContext); + const shouldIndent = hasLeft && !left && !right && !leading && !trailing; const [isDescriptionMultiline, setIsDescriptionMultiline] = React.useState(false); diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index fe2697c38d..f9fb10c66a 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -1,9 +1,8 @@ import { StyleSheet, View } from 'react-native'; -import { describe, expect, it } from '@jest/globals'; +import { describe, expect, it, jest } from '@jest/globals'; -import { getTheme } from '../../core/theming'; -import { fireEvent, render, screen } from '../../test-utils'; +import { act, fireEvent, render, screen, userEvent } from '../../test-utils'; import { red500 } from '../../theme/colors'; import { LightTheme } from '../../theme/schemes'; import ListAccordion from '../List/ListAccordion'; @@ -122,6 +121,52 @@ it('does not indent expanded accordion children when the accordion has no left i }); }); +it.each([ + ['the leading slot', { leading: }], + ['the trailing slot', { trailing: }], +])( + 'does not indent expanded accordion children that use %s', + async (_label, slots) => { + await render( + } + title="Accordion with indented children" + expanded + > + + + ); + + expect(screen.getByTestId('accordion-child')).not.toHaveStyle({ + paddingLeft: 40, + }); + } +); + +it('keeps the content on screen until the collapse animation ends', async () => { + await render( + + + + ); + + expect(screen.queryByText('List item 1')).not.toBeOnTheScreen(); + + await userEvent.press(screen.getByText('Accordion item 1')); + + expect(screen.getByText('List item 1')).toBeOnTheScreen(); + + await userEvent.press(screen.getByText('Accordion item 1')); + + expect(screen.getByText('List item 1')).toBeOnTheScreen(); + + await act(() => { + jest.runAllTimers(); + }); + + expect(screen.queryByText('List item 1')).not.toBeOnTheScreen(); +}); + describe('ListAccordion', () => { it('should not throw an error when id={0}', async () => { const ListAccordionTest = () => ( diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index 93e6f6398c..a68d1d49a5 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -176,75 +176,71 @@ exports[`renders expanded accordion 1`] = ` @@ -252,49 +248,61 @@ exports[`renders expanded accordion 1`] = ` style={ [ { - "paddingLeft": 16, - }, - { - "flexGrow": 1, - "flexShrink": 1, - "justifyContent": "center", + "flexDirection": "row", + "width": "100%", }, undefined, ] } > - + - List item 1 - + ] + } + > + List item 1 + + From 97d6651b5b05cf9ebea781ecdd4c8291beed5c6f Mon Sep 17 00:00:00 2001 From: Jacek Paciorek Date: Thu, 12 Nov 2026 11:03:15 +0100 Subject: [PATCH 14/16] test(list): check the row height with a List.Image thumbnail --- src/components/List/ListImage.tsx | 6 ++ src/components/__tests__/ListItem.test.tsx | 67 +++++++++++++++------- 2 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/components/List/ListImage.tsx b/src/components/List/ListImage.tsx index 73a2ba3692..7b10d3f23f 100644 --- a/src/components/List/ListImage.tsx +++ b/src/components/List/ListImage.tsx @@ -10,6 +10,10 @@ export type Props = { source: ImageSourcePropType; variant?: 'image' | 'video'; style?: StyleProp; + /** + * TestID used for testing purposes + */ + testID?: string; /** * @optional */ @@ -38,6 +42,7 @@ const ListImage = ({ style, source, variant = 'image', + testID, theme: _theme, }: Props) => { const { verticalPadding } = React.useContext(ListRowContext); @@ -60,6 +65,7 @@ const ListImage = ({ ); diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 290c58a5f9..41c25589a3 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -11,6 +11,7 @@ import { red500 } from '../../theme/colors'; import Chip from '../Chip/Chip'; import IconButton from '../IconButton/IconButton'; import ListIcon from '../List/ListIcon'; +import ListImage from '../List/ListImage'; import ListItem from '../List/ListItem'; const styles = StyleSheet.create({ @@ -23,18 +24,6 @@ const styles = StyleSheet.create({ content: { paddingLeft: 0, }, - avatar: { - width: 40, - height: 40, - }, - image: { - width: 56, - height: 56, - }, - video: { - width: 114, - height: 64, - }, }); const testID = 'list-item'; @@ -224,31 +213,65 @@ it('hits the two and three line container heights without measuring', async () = }); }); +// The row is 88dp tall: 2 * padding + 2 * margin + the 64dp thumbnail. it.each([ - ['a 40dp accessory', styles.avatar, undefined, 56], - ['a 56dp accessory', styles.image, 'Item description', 72], - ['a 64dp accessory', styles.video, undefined, 56], + ['one line', undefined, false, 8, 4], + ['two line', 'Item description', false, 8, 4], + ['three line', 'Item description', true, 12, 0], ])( - 'keeps the container height with %s in the leading slot', - async (_label, accessoryStyle, description, minHeight) => { + 'makes a %s row with a video thumbnail 88dp tall', + async (_label, description, wrapsDescription, padding, margin) => { await render( ( - - )} + leading={ + + } testID={testID} /> ); + if (wrapsDescription) { + await fireEvent(screen.getByText('Item description'), 'textLayout', { + nativeEvent: { lines: [{}, {}] }, + }); + } + expect(screen.getByTestId(testID)).toHaveStyle({ - minHeight, - paddingVertical: 8, + paddingVertical: padding, + }); + expect(screen.getByTestId('video-thumbnail')).toHaveStyle({ + height: 64, + marginVertical: margin, }); } ); +it('does not add vertical margin to an image thumbnail', async () => { + await render( + + } + testID={testID} + /> + ); + + expect(screen.getByTestId('image-thumbnail')).toHaveStyle({ + height: 56, + marginVertical: undefined, + }); +}); + it('colors the typed slots from the list item context', async () => { await render( Date: Thu, 12 Nov 2026 13:23:50 +0100 Subject: [PATCH 15/16] chore(comments): remove unnecessary comments --- src/components/List/ListAccordion.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 987fa227b9..89dae2f387 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -282,8 +282,6 @@ const ListAccordion = ({ ); const [contentHeight, setContentHeight] = React.useState(0); - // Start the transition in the render where `isExpanded` changes, so the - // content is mounted and measured before the first animation frame. if ( isExpanded && (contentPhase === 'collapsed' || contentPhase === 'collapsing') @@ -299,8 +297,6 @@ const ListAccordion = ({ const contentProgress = useSharedValue(isExpanded ? 1 : 0); React.useEffect(() => { - // An interrupted animation reports `finished: false`, and a stale one - // cannot move the phase because the phase no longer matches. const finishTransition = (finished: boolean) => { if (!finished) { return; @@ -326,10 +322,6 @@ const ListAccordion = ({ ); }, [isExpanded, contentProgress, timingConfig]); - // The wrapper height changes in layout, so the rows below the accordion - // move with it. When the transition ends, the height goes back to `auto` - // so that content which changes size (for example, a nested accordion) - // is not clipped. const contentTransitionStyle = useAnimatedStyle(() => ({ height: contentPhase === 'expanded' From 2eec35324f0b08261fbf6b62e1585c1e494b0979 Mon Sep 17 00:00:00 2001 From: Jacek Paciorek Date: Mon, 16 Nov 2026 16:33:10 +0100 Subject: [PATCH 16/16] fix(list): rebase fix --- example/src/Examples/ListItemExample.tsx | 40 +++++++++++-- src/components/List/ListAccordion.tsx | 13 +++-- src/components/List/ListItem.tsx | 7 +++ src/components/List/utils.ts | 9 ++- .../__tests__/ListAccordion.test.tsx | 8 +-- src/components/__tests__/ListImage.test.tsx | 10 ---- src/components/__tests__/ListItem.test.tsx | 2 +- .../__snapshots__/ListAccordion.test.tsx.snap | 28 --------- .../__snapshots__/ListImage.test.tsx.snap | 3 + .../__snapshots__/ListItem.test.tsx.snap | 57 ++++++++++++------- .../__snapshots__/ListSection.test.tsx.snap | 6 ++ 11 files changed, 108 insertions(+), 75 deletions(-) diff --git a/example/src/Examples/ListItemExample.tsx b/example/src/Examples/ListItemExample.tsx index 030d21cef8..83a61e34e7 100644 --- a/example/src/Examples/ListItemExample.tsx +++ b/example/src/Examples/ListItemExample.tsx @@ -49,7 +49,13 @@ const ListItemExample = () => { } + right={(props) => ( + + )} /> @@ -85,7 +91,13 @@ const ListItemExample = () => { title="Headline" description="Supporting text that is long enough to fill up multiple lines in the item" left={(props) => } - right={(props) => } + right={(props) => ( + + )} /> @@ -133,7 +145,13 @@ const ListItemExample = () => { left={(props) => ( )} - right={(props) => } + right={(props) => ( + + )} /> @@ -199,7 +217,13 @@ const ListItemExample = () => { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={(props) => } + right={(props) => ( + + )} /> @@ -271,7 +295,13 @@ const ListItemExample = () => { source={require('../../../example/assets/images/strawberries.jpg')} /> )} - right={(props) => } + right={(props) => ( + + )} /> diff --git a/src/components/List/ListAccordion.tsx b/src/components/List/ListAccordion.tsx index 89dae2f387..2a87754663 100644 --- a/src/components/List/ListAccordion.tsx +++ b/src/components/List/ListAccordion.tsx @@ -4,7 +4,6 @@ import type { ColorValue, GestureResponderEvent, LayoutChangeEvent, - NativeSyntheticEvent, PressableAndroidRippleConfig, StyleProp, TextLayoutEvent, @@ -24,9 +23,10 @@ import Animated, { } from 'react-native-reanimated'; import { scheduleOnRN } from 'react-native-worklets'; +import { ListAccordionContext } from './ListAccordionContext'; import { ListAccordionGroupContext } from './ListAccordionGroup'; import { ListTokens } from './tokens'; -import type { ListChildProps, Style } from './utils'; +import type { Style } from './utils'; import { ListRowContext, getAccordionColors, getLeftStyles } from './utils'; import { useLocale } from '../../core/locale'; import { useInternalTheme } from '../../core/theming'; @@ -355,6 +355,9 @@ const ListAccordion = ({ [isDescriptionMultiline] ); + const hasLeft = left != null; + const accordionContext = React.useMemo(() => ({ hasLeft }), [hasLeft]); + return ( { +}): { + descriptionColor: ColorValue; + titleTextColor: ColorValue; + leadingIconColor: ColorValue; + trailingIconColor: ColorValue; +} => { const selectedContentColor = theme.colors[ListTokens.selectedContentColor]; return { diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx index f9fb10c66a..bea874bbef 100644 --- a/src/components/__tests__/ListAccordion.test.tsx +++ b/src/components/__tests__/ListAccordion.test.tsx @@ -221,7 +221,7 @@ describe('ListAccordion', () => { ); expect(screen.getByText('Accordion item 1')).toHaveStyle({ - color: getTheme().colors.onSurface, + color: LightTheme.colors.onSurface, }); }); @@ -276,7 +276,7 @@ describe('ListAccordion', () => { expect( screen.getByText('chevron-down', { includeHiddenElements: true }) ).toHaveStyle({ - color: getTheme().colors.onSurface, + color: LightTheme.colors.onSurface, }); }); @@ -307,10 +307,10 @@ describe('ListAccordion', () => { ); expect(screen.getByText('Accordion item 1')).toHaveStyle({ - color: getTheme().colors.onPrimaryContainer, + color: LightTheme.colors.onPrimaryContainer, }); expect(screen.getByText('Supporting')).toHaveStyle({ - color: getTheme().colors.onPrimaryContainer, + color: LightTheme.colors.onPrimaryContainer, }); }); }); diff --git a/src/components/__tests__/ListImage.test.tsx b/src/components/__tests__/ListImage.test.tsx index 39fc779755..04796fd73a 100644 --- a/src/components/__tests__/ListImage.test.tsx +++ b/src/components/__tests__/ListImage.test.tsx @@ -6,16 +6,6 @@ import { render } from '../../test-utils'; import ListImage from '../List/ListImage'; const styles = StyleSheet.create({ - image: { - width: 56, - height: 56, - }, - video: { - width: 114, - height: 64, - marginLeft: 0, - marginVertical: 4, - }, container: { width: 30, height: 56, diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx index 41c25589a3..1c15550432 100644 --- a/src/components/__tests__/ListItem.test.tsx +++ b/src/components/__tests__/ListItem.test.tsx @@ -5,9 +5,9 @@ import { Text, View } from 'react-native'; import { expect, it, jest } from '@jest/globals'; import { userEvent } from '@testing-library/react-native'; -import { getTheme } from '../../core/theming'; import { fireEvent, render, screen } from '../../test-utils'; import { red500 } from '../../theme/colors'; +import { LightTheme } from '../../theme/schemes'; import Chip from '../Chip/Chip'; import IconButton from '../IconButton/IconButton'; import ListIcon from '../List/ListIcon'; diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap index a68d1d49a5..7b74b8b7f7 100644 --- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap @@ -193,35 +193,7 @@ exports[`renders expanded accordion 1`] = ` style={null} > diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap index 1b7f914bec..df64e88106 100644 --- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap @@ -8,9 +8,18 @@ exports[`renders list item with custom content style 1`] = ` false, [ { - "paddingRight": 24, + "justifyContent": "center", + "paddingRight": 16, "paddingVertical": 8, }, + { + "minHeight": 72, + }, + false, + false, + { + "backgroundColor": undefined, + }, undefined, ], ] @@ -22,7 +31,6 @@ exports[`renders list item with custom content style 1`] = ` [ { "flexDirection": "row", - "marginVertical": 6, "width": "100%", }, undefined, @@ -56,21 +64,22 @@ exports[`renders list item with custom content style 1`] = ` }, { "color": "rgba(29, 27, 32, 1)", - "fontFamily": "System", - "fontWeight": "400", - "letterSpacing": 0, - }, - { "writingDirection": "ltr", }, [ { + "fontFamily": "System", "fontSize": 16, + "fontWeight": "400", + "letterSpacing": 0.5, + "lineHeight": 24, }, - { - "color": "rgba(29, 27, 32, 1)", - }, - undefined, + [ + { + "color": "rgba(29, 27, 32, 1)", + }, + undefined, + ], ], ] } @@ -88,21 +97,22 @@ exports[`renders list item with custom content style 1`] = ` }, { "color": "rgba(29, 27, 32, 1)", - "fontFamily": "System", - "fontWeight": "400", - "letterSpacing": 0, - }, - { "writingDirection": "ltr", }, [ { + "fontFamily": "System", "fontSize": 14, + "fontWeight": "400", + "letterSpacing": 0.25, + "lineHeight": 20, }, - { - "color": "rgba(73, 69, 79, 1)", - }, - undefined, + [ + { + "color": "rgba(73, 69, 79, 1)", + }, + undefined, + ], ], ] } @@ -130,6 +140,7 @@ exports[`renders list item with custom description 1`] = ` "minHeight": 72, }, false, + false, { "backgroundColor": undefined, }, @@ -499,6 +510,7 @@ exports[`renders list item with custom title and description styles 1`] = ` "minHeight": 72, }, false, + false, { "backgroundColor": undefined, }, @@ -624,6 +636,7 @@ exports[`renders list item with left and right items 1`] = ` "minHeight": 72, }, false, + false, { "backgroundColor": undefined, }, @@ -794,6 +807,7 @@ exports[`renders list item with left item 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -929,6 +943,7 @@ exports[`renders list item with right item 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -1020,6 +1035,7 @@ exports[`renders list item with title and description 1`] = ` "minHeight": 72, }, false, + false, { "backgroundColor": undefined, }, @@ -1141,6 +1157,7 @@ exports[`renders with a description with typeof number 1`] = ` "minHeight": 72, }, false, + false, { "backgroundColor": undefined, }, diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap index 91aee138d2..5d4b67c9bb 100644 --- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap @@ -468,6 +468,7 @@ exports[`renders list section with custom title style 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -600,6 +601,7 @@ exports[`renders list section with custom title style 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -1186,6 +1188,7 @@ exports[`renders list section with subheader 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -1318,6 +1321,7 @@ exports[`renders list section with subheader 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -1864,6 +1868,7 @@ exports[`renders list section without subheader 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, }, @@ -1996,6 +2001,7 @@ exports[`renders list section without subheader 1`] = ` "minHeight": 56, }, false, + false, { "backgroundColor": undefined, },