diff --git a/docs/6.x/docs/guides/migration.md b/docs/6.x/docs/guides/migration.md
index 0b0b13c650..c55b90b22d 100644
--- a/docs/6.x/docs/guides/migration.md
+++ b/docs/6.x/docs/guides/migration.md
@@ -1451,8 +1451,66 @@ The `style` prop of `Card.Cover` is now typed as a `View` style. Image style pro
### List
+#### Size and typography
+
+`List.Item` and `List.Accordion` now use the Material Design 3 list sizes and the typography of the theme:
+
+- Rows are 56dp tall with one line, 72dp with two lines and 88dp with three lines.
+- A three-line row has 12dp of vertical padding instead of 8dp.
+- The space after the trailing element is 16dp instead of 24dp.
+- The title uses the `bodyLarge` font of the theme instead of `fontSize` 16. The description uses `bodyMedium` instead of `fontSize` 14.
+
+To keep the 24dp trailing space of 5.x, set it in `style`:
+
+```diff
+-
++
+```
+
+#### `List.Item`
+
+`List.Item` has new `leading` and `trailing` props. They take an element, not a render function, and `List.Icon` in them gets the icon color of the row. The `left` and `right` props of `List.Item` are deprecated and will be removed in 7.0. `List.Accordion` keeps `left` and `right`.
+
+```diff
+ }
++ leading={}
+/>
+```
+
+A `List.Item` with `onPress` now has the `button` role, so screen readers announce it as a button. If your tests find elements with `getByRole('button')`, these rows now match too.
+
+`List.Item` and `List.Accordion` have a new `selected` prop. A selected row uses `secondaryContainer` for its background and `onSecondaryContainer` for its title, description and icons. Screen readers announce it as selected. On web, `aria-selected` is not valid on the `button` role, so a row with that role uses `aria-pressed` instead. If you highlighted a row with your own `style` and `titleStyle`, you can use `selected` instead:
+
+```diff
+
+```
+
+A disabled `List.Item` now looks disabled. In 5.x, `disabled` only stopped presses. The title, description and the icons in `leading` and `trailing` are `onSurface`, and the row content is at 38% opacity. A selected, disabled row has an `onSurface` background at 38% opacity instead of `secondaryContainer`. `List.Accordion` has a new `disabled` prop that works the same way and also stops the accordion from expanding or collapsing.
+
#### `List.Accordion`
+The header keeps its colors when the accordion expands. In 5.x, the title and the `left` icon turned `primary`. The header background is `surface` instead of `background`, and the chevron is `onSurface` instead of `onSurfaceVariant`. The chevron rotates instead of switching to `chevron-up`.
+
+To keep the `primary` title of an expanded accordion, set it in `titleStyle`:
+
+```diff
+ setExpanded(!expanded)}
++ titleStyle={expanded ? { color: theme.colors.primary } : undefined}
+>
+```
+
+The content now animates its height when the accordion expands or collapses. It stays mounted until the collapse animation ends, so it unmounts later than in 5.x.
+
An accordion with a `left` element now indents only its `List.Item` children. Anything else you put inside keeps its own padding, so indent it yourself to line it up with the items.
```tsx
@@ -1473,6 +1531,10 @@ An accordion with a `left` element now indents only its `List.Item` children. An
`theme` set on `List.Accordion` no longer reaches its children either. Pass it to the child that needs the override.
+#### `List.Image`
+
+`List.Image` with `variant="video"` now has a vertical margin, so a row with a video thumbnail is 88dp tall for one, two or three lines.
+
### IconButton
`IconButton` now follows the Material 3 Expressive spec. The color modes, size API, and toggle `selected` behavior have changed. Passing the old numeric `size` (for example `size={24}`) crashes at runtime, because `size` is now a named token and `IconButtonTokens.sizes[24]` is `undefined`.
diff --git a/example/src/Examples/ListAccordionExample.tsx b/example/src/Examples/ListAccordionExample.tsx
index 58c3841de5..c3182a595a 100644
--- a/example/src/Examples/ListAccordionExample.tsx
+++ b/example/src/Examples/ListAccordionExample.tsx
@@ -29,6 +29,13 @@ const ListAccordionExample = () => {
>
+ }
+ title="Selected"
+ selected
+ >
+
+
@@ -47,11 +54,11 @@ const ListAccordionExample = () => {
title="Accordion item 1"
>
}
+ leading={}
title="List item 1"
/>
}
+ leading={}
title="List item 2"
/>
diff --git a/example/src/Examples/ListItemExample.tsx b/example/src/Examples/ListItemExample.tsx
index f91eb04081..0d91ed8678 100644
--- a/example/src/Examples/ListItemExample.tsx
+++ b/example/src/Examples/ListItemExample.tsx
@@ -1,18 +1,55 @@
-import { View, StyleSheet } from 'react-native';
+import { useState } from 'react';
import { List, Divider, Checkbox, Avatar, Switch } from 'react-native-paper';
import ScreenWrapper from '../ScreenWrapper';
-const CenteredCheckbox = () => (
-
-
-
-);
+const SelectableSection = () => {
+ const [selected, setSelected] = useState(0);
+
+ return (
+
+ {[0, 1, 2].map((index) => (
+ setSelected(index)}
+ leading={}
+ />
+ ))}
+
+
+ );
+};
const ListItemExample = () => {
return (
+
+
+
+ {}}
+ leading={}
+ trailing={}
+ />
+ {}}
+ leading={}
+ trailing={}
+ />
+
+
+
@@ -21,16 +58,19 @@ const ListItemExample = () => {
description="Supporting text that is long enough to fill up multiple lines in the item"
/>
- } />
+ }
+ />
}
+ trailing={}
/>
}
+ trailing={}
/>
@@ -38,35 +78,35 @@ const ListItemExample = () => {
}
+ leading={}
/>
}
+ leading={}
/>
}
+ leading={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
@@ -74,47 +114,35 @@ const ListItemExample = () => {
(
-
- )}
+ leading={}
/>
(
-
- )}
+ leading={}
/>
(
-
- )}
+ leading={}
/>
(
-
- )}
- right={() => }
+ leading={}
+ trailing={}
/>
(
-
- )}
- right={() => }
+ leading={}
+ trailing={}
/>
(
-
- )}
- right={() => }
+ leading={}
+ trailing={}
/>
@@ -122,65 +150,59 @@ const ListItemExample = () => {
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
@@ -188,107 +210,98 @@ const ListItemExample = () => {
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
+ }
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
(
+ leading={
- )}
- right={() => }
+ }
+ trailing={}
/>
- }
- />
+ } />
}
+ trailing={}
/>
}
+ trailing={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
}
- right={() => }
+ leading={}
+ trailing={}
/>
@@ -296,12 +309,6 @@ const ListItemExample = () => {
);
};
-const styles = StyleSheet.create({
- centered: {
- alignSelf: 'center',
- },
-});
-
ListItemExample.title = 'List.Item';
export default ListItemExample;
diff --git a/example/src/Examples/ListSectionExample.tsx b/example/src/Examples/ListSectionExample.tsx
index d7efbe6adc..fe0d774029 100644
--- a/example/src/Examples/ListSectionExample.tsx
+++ b/example/src/Examples/ListSectionExample.tsx
@@ -9,42 +9,42 @@ const ListSectionExample = () => {
Single line
}
+ leading={}
title="List item 1"
/>
}
+ leading={}
title="List item 2"
/>
}
- right={(props) => }
+ leading={}
+ trailing={}
/>
Two line
(
+ leading={
- )}
+ }
title="List item 1"
description="Describes item 1"
/>
(
+ leading={
- )}
- right={(props) => }
+ }
+ trailing={}
title="List item 2"
description="Describes item 2"
/>
@@ -53,25 +53,25 @@ const ListSectionExample = () => {
Three line
(
+ leading={
- )}
+ }
title="List item 1"
description="Describes item 1. Example of a very very long description."
/>
(
+ leading={
- )}
- right={(props) => }
+ }
+ trailing={}
title="List item 2"
description="Describes item 2. Example of a very very long description."
/>
@@ -80,14 +80,14 @@ const ListSectionExample = () => {
Custom title and description
(
+ leading={
- )}
- right={(props) => }
+ }
+ trailing={}
title={({ ellipsizeMode, color: titleColor, fontSize }) => (
(
expandedProp || false
);
- const [alignToTop, setAlignToTop] = React.useState(false);
-
- const onDescriptionTextLayout = (event: TextLayoutEvent) => {
- const { nativeEvent } = event;
- setAlignToTop(nativeEvent.lines.length >= 2);
- };
+ const { isDescriptionMultiline, onDescriptionTextLayout, rowContext } =
+ useListRow();
const handlePressAction = (e: GestureResponderEvent) => {
onPress?.(e);
@@ -230,10 +262,92 @@ const ListAccordion = ({
? groupContext.expandedId === id
: expandedInternal;
- const { descriptionColor, titleTextColor } = getAccordionColors({
- theme,
- isExpanded,
- });
+ 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 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'
+ );
+ // A shared value, so a nested accordion that animates does not re-render
+ // this one on every frame
+ const contentHeight = useSharedValue(0);
+
+ 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(() => {
+ const finishTransition = (finished: boolean) => {
+ if (!finished) {
+ return;
+ }
+
+ setContentPhase((phase) => {
+ if (isExpanded && phase === 'expanding') {
+ return 'expanded';
+ }
+
+ if (!isExpanded && phase === 'collapsing') {
+ return 'collapsed';
+ }
+
+ return phase;
+ });
+ };
+
+ contentProgress.value = withTiming(
+ isExpanded ? 1 : 0,
+ timingConfig,
+ (finished) => scheduleOnRN(finishTransition, finished ?? false)
+ );
+ }, [isExpanded, contentProgress, timingConfig]);
+
+ const contentTransitionStyle = useAnimatedStyle(() => ({
+ height:
+ contentPhase === 'expanded'
+ ? 'auto'
+ : contentProgress.value * contentHeight.value,
+ opacity: contentProgress.value,
+ }));
+
+ const onContentLayout = (event: LayoutChangeEvent) => {
+ contentHeight.value = event.nativeEvent.layout.height;
+ };
+
+ const { titleColor, descriptionColor, leadingIconColor, expandIconColor } =
+ getListColors({ theme, selected, disabled });
const handlePress =
groupContext && id !== undefined
@@ -245,94 +359,129 @@ const ListAccordion = ({
return (
-
-
-
+ {selected && disabled ? (
+
+ ) : null}
+
+
- {left
- ? left({
- color: isExpanded ? theme.colors?.primary : descriptionColor,
- style: getLeftStyles(alignToTop, description),
- })
- : null}
-
-
- {title}
-
- {description ? (
+
+ {left
+ ? left({
+ color: leadingIconColor,
+ style: getAccessoryStyles(
+ isDescriptionMultiline,
+ description
+ ),
+ })
+ : null}
+
- {description}
+ {title}
- ) : null}
-
-
- {right ? (
- right({
- isExpanded: isExpanded,
- })
- ) : (
-
- )}
+ {description ? (
+
+ {description}
+
+ ) : null}
+
+
+ {right ? (
+ right({
+ isExpanded: isExpanded,
+ })
+ ) : (
+
+
+
+ )}
+
-
-
+
+
- {isExpanded ? (
-
- {children}
-
+ {contentPhase !== 'collapsed' ? (
+
+
+
+ {children}
+
+
+
) : null}
);
@@ -341,31 +490,24 @@ const ListAccordion = ({
ListAccordion.displayName = 'List.Accordion';
const styles = StyleSheet.create({
- container: {
- paddingVertical: 8,
- paddingRight: 24,
- },
row: {
flexDirection: 'row',
- marginVertical: 6,
- },
- multiline: {
- height: 40,
- alignItems: 'center',
- justifyContent: 'center',
- },
- title: {
- fontSize: 16,
- },
- description: {
- fontSize: 14,
},
contentItem: {
- paddingLeft: 16,
+ paddingLeft: ListTokens.leadingSpace,
},
trailingItem: {
- marginVertical: 6,
- paddingLeft: 8,
+ alignSelf: 'center',
+ paddingLeft: ListTokens.leadingSpace,
+ },
+ transitioningClip: {
+ overflow: 'hidden',
+ },
+ transitioningContent: {
+ position: 'absolute',
+ top: 0,
+ left: 0,
+ right: 0,
},
content: {
flex: 1,
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/ListImage.tsx b/src/components/List/ListImage.tsx
index 213d4254c7..5c7ce1689c 100644
--- a/src/components/List/ListImage.tsx
+++ b/src/components/List/ListImage.tsx
@@ -1,12 +1,20 @@
+import * as React from 'react';
import { StyleSheet, Image } from 'react-native';
import type { StyleProp, ImageSourcePropType, ImageStyle } from 'react-native';
+import { ListItemContext } from './ListItemContext';
+import { ListTokens } from './tokens';
+import { ListRowContext } from './utils';
import type { ThemeProp } from '../../theme/types';
export type Props = {
source: ImageSourcePropType;
variant?: 'image' | 'video';
style?: StyleProp;
+ /**
+ * TestID used for testing purposes
+ */
+ testID?: string;
/**
* @optional
*/
@@ -35,11 +43,24 @@ const ListImage = ({
style,
source,
variant = 'image',
+ testID,
theme: _theme,
}: Props) => {
+ const { verticalPadding } = React.useContext(ListRowContext);
+ // The `leading` slot adds the leading space around the image, but a video
+ // thumbnail sits flush with the row's start edge
+ const inLeadingSlot = React.useContext(ListItemContext)?.slot === 'leading';
+
const getStyles = () => {
if (variant === 'video') {
- return [style, styles.video];
+ return [
+ style,
+ styles.video,
+ {
+ marginVertical: ListTokens.threeLineVerticalPadding - verticalPadding,
+ },
+ inLeadingSlot && styles.videoInLeadingSlot,
+ ];
}
return [style, styles.image];
@@ -49,6 +70,7 @@ const ListImage = ({
);
@@ -64,6 +86,9 @@ const styles = StyleSheet.create({
height: 64,
marginLeft: 0,
},
+ videoInLeadingSlot: {
+ marginLeft: -ListTokens.leadingSpace,
+ },
});
ListImage.displayName = 'List.Image';
diff --git a/src/components/List/ListItem.tsx b/src/components/List/ListItem.tsx
index 659abf9774..3c9878a67b 100644
--- a/src/components/List/ListItem.tsx
+++ b/src/components/List/ListItem.tsx
@@ -4,14 +4,25 @@ import type {
ColorValue,
GestureResponderEvent,
StyleProp,
- TextLayoutEvent,
TextProps,
TextStyle,
ViewStyle,
} from 'react-native';
import { ListAccordionContext } from './ListAccordionContext';
-import { getLeftStyles, getRightStyles } from './utils';
+import { ListItemContext } from './ListItemContext';
+import ListSelectedDisabledLayer from './ListSelectedDisabledLayer';
+import { ListTokens } from './tokens';
+import {
+ ListRowContext,
+ getAccessoryStyles,
+ getListColors,
+ getRowContainerStyles,
+ getRowContentStyle,
+ getSelectedContainerColor,
+ getSelectedStateProps,
+ useListRow,
+} from './utils';
import type { Style } from './utils';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../theme/types';
@@ -49,14 +60,33 @@ 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.
+ * @deprecated Use `leading` instead. `left` will be removed in 7.0.
*/
left?: (props: { color: ColorValue; style: Style }) => React.ReactNode;
/**
* Callback which returns a React element to display on the right side.
+ * @deprecated Use `trailing` instead. `right` will be removed in 7.0.
*/
right?: (props: { color: ColorValue; style?: Style }) => React.ReactNode;
+ /**
+ * Whether to highlight the list item as selected.
+ */
+ selected?: boolean;
+ /**
+ * Whether the list item is disabled. A disabled item does not respond to
+ * presses, and its content is shown at 38% opacity.
+ */
+ disabled?: boolean;
/**
* Function to execute on press.
*/
@@ -134,7 +164,7 @@ export type Props = Omit<
* }
+ * leading={}
* />
* );
*
@@ -146,8 +176,12 @@ export type Props = Omit<
const ListItem = ({
left,
right,
+ leading,
+ trailing,
title,
description,
+ selected,
+ disabled,
onPress,
theme: themeOverrides,
style,
@@ -167,13 +201,21 @@ const ListItem = ({
}: Props) => {
const theme = useInternalTheme(themeOverrides);
const { hasLeft } = React.useContext(ListAccordionContext);
- const shouldIndent = hasLeft && !left && !right;
- const [alignToTop, setAlignToTop] = React.useState(false);
+ const shouldIndent = hasLeft && !left && !right && !leading && !trailing;
+ const { isDescriptionMultiline, onDescriptionTextLayout, rowContext } =
+ useListRow();
- const onDescriptionTextLayout = (event: TextLayoutEvent) => {
- const { nativeEvent } = event;
- setAlignToTop(nativeEvent.lines.length >= 2);
- };
+ const backgroundColor = getSelectedContainerColor({
+ theme,
+ selected,
+ disabled,
+ });
+ const {
+ titleColor,
+ descriptionColor,
+ leadingIconColor: leadingColor,
+ trailingIconColor: trailingColor,
+ } = getListColors({ theme, selected, disabled });
const renderDescription = (
descriptionColor: ColorValue,
@@ -184,18 +226,16 @@ const ListItem = ({
selectable: false,
ellipsizeMode: descriptionEllipsizeMode,
color: descriptionColor,
- fontSize: styles.description.fontSize,
+ fontSize: theme.fonts.bodyMedium.fontSize,
})
) : (
@@ -205,21 +245,21 @@ const ListItem = ({
};
const renderTitle = () => {
- const titleColor = theme.colors.onSurface;
-
return typeof title === 'function' ? (
title({
selectable: false,
ellipsizeMode: titleEllipsizeMode,
color: titleColor,
- fontSize: styles.title.fontSize,
+ fontSize: theme.fonts.bodyLarge.fontSize,
})
) : (
{title}
@@ -227,71 +267,108 @@ const ListItem = ({
);
};
- const descriptionColor = theme.colors.onSurfaceVariant;
+ const leadingContext = React.useMemo(
+ () => ({ color: leadingColor, slot: 'leading' as const }),
+ [leadingColor]
+ );
+ const trailingContext = React.useMemo(
+ () => ({ color: trailingColor, slot: 'trailing' as const }),
+ [trailingColor]
+ );
+
+ const renderLeading = () => {
+ const accessoryStyle = getAccessoryStyles(
+ isDescriptionMultiline,
+ description
+ );
+
+ if (leading) {
+ return (
+
+ {leading}
+
+ );
+ }
+
+ return left ? left({ color: leadingColor, style: accessoryStyle }) : null;
+ };
+
+ const renderTrailing = () => {
+ const accessoryStyle = getAccessoryStyles(
+ isDescriptionMultiline,
+ description
+ );
+
+ if (trailing) {
+ return (
+
+ {trailing}
+
+ );
+ }
+
+ return right
+ ? right({ color: trailingColor, style: accessoryStyle })
+ : null;
+ };
+
+ // A caller's own role wins, so the selected state follows it
+ const role = rest.role ?? (onPress ? 'button' : undefined);
return (
-
-
- {left
- ? left({
- color: descriptionColor,
- style: getLeftStyles(alignToTop, description),
- })
- : null}
-
- {renderTitle()}
+
+
+ {selected && disabled ? (
+
+ ) : null}
+
+ {renderLeading()}
+
+ {renderTitle()}
- {description
- ? renderDescription(descriptionColor, description)
- : null}
+ {description
+ ? renderDescription(descriptionColor, description)
+ : null}
+
+ {renderTrailing()}
- {right
- ? right({
- color: descriptionColor,
- style: getRightStyles(alignToTop, description),
- })
- : null}
-
-
+
+
);
};
ListItem.displayName = 'List.Item';
const styles = StyleSheet.create({
- container: {
- paddingVertical: 8,
- paddingRight: 24,
- },
indent: {
paddingLeft: 40,
},
row: {
width: '100%',
flexDirection: 'row',
- marginVertical: 6,
- },
- title: {
- fontSize: 16,
- },
- description: {
- fontSize: 14,
},
item: {
- paddingLeft: 16,
+ paddingLeft: ListTokens.leadingSpace,
},
content: {
flexShrink: 1,
diff --git a/src/components/List/ListItemContext.tsx b/src/components/List/ListItemContext.tsx
new file mode 100644
index 0000000000..6e6ad40e56
--- /dev/null
+++ b/src/components/List/ListItemContext.tsx
@@ -0,0 +1,11 @@
+import * as React from 'react';
+import type { ColorValue } from 'react-native';
+
+export type ListItemContextType = {
+ color: ColorValue;
+ slot: 'leading' | 'trailing';
+};
+
+export const ListItemContext = React.createContext(
+ null
+);
diff --git a/src/components/List/ListSection.tsx b/src/components/List/ListSection.tsx
index cd623992d6..5fd7d66f04 100644
--- a/src/components/List/ListSection.tsx
+++ b/src/components/List/ListSection.tsx
@@ -37,10 +37,10 @@ export type Props = ViewProps & {
* const MyComponent = () => (
*
* Some title
- * } />
+ * } />
* }
+ * leading={}
* />
*
* );
diff --git a/src/components/List/ListSelectedDisabledLayer.tsx b/src/components/List/ListSelectedDisabledLayer.tsx
new file mode 100644
index 0000000000..99d568edad
--- /dev/null
+++ b/src/components/List/ListSelectedDisabledLayer.tsx
@@ -0,0 +1,30 @@
+import { StyleSheet, View } from 'react-native';
+
+import { ListTokens } from './tokens';
+import type { InternalTheme } from '../../theme/types';
+
+/**
+ * The MD3 container of a selected, disabled row: `onSurface` at 38% opacity.
+ * It is a separate layer, so the opacity does not also fade the row content.
+ */
+const ListSelectedDisabledLayer = ({ theme }: { theme: InternalTheme }) => (
+
+);
+
+const styles = StyleSheet.create({
+ layer: {
+ ...StyleSheet.absoluteFill,
+ pointerEvents: 'none',
+ },
+});
+
+export default ListSelectedDisabledLayer;
diff --git a/src/components/List/tokens.ts b/src/components/List/tokens.ts
new file mode 100644
index 0000000000..f418b9dde1
--- /dev/null
+++ b/src/components/List/tokens.ts
@@ -0,0 +1,31 @@
+import { tokens } from '../../theme/tokens';
+import type { ColorRole } from '../../theme/types';
+
+const sizes = {
+ verticalPadding: 8,
+ threeLineVerticalPadding: 12,
+ oneLineContainerHeight: 56,
+ twoLineContainerHeight: 72,
+ leadingSpace: 16,
+ trailingSpace: 16,
+} as const;
+
+const opacities = {
+ disabledContentOpacity: tokens.md.sys.state.opacity.disabled,
+ selectedDisabledContainerOpacity: tokens.md.sys.state.opacity.disabled,
+} as const;
+
+const colors = {
+ containerColor: 'surface',
+ headlineColor: 'onSurface',
+ supportingTextColor: 'onSurfaceVariant',
+ leadingIconColor: 'onSurfaceVariant',
+ trailingIconColor: 'onSurfaceVariant',
+ expandTrailingIconColor: 'onSurface',
+ selectedContainerColor: 'secondaryContainer',
+ selectedContentColor: 'onSecondaryContainer',
+ disabledContentColor: 'onSurface',
+ selectedDisabledContainerColor: 'onSurface',
+} as const satisfies Record;
+
+export const ListTokens = { ...sizes, ...opacities, ...colors };
diff --git a/src/components/List/utils.ts b/src/components/List/utils.ts
index 25e5ccd1d1..e1e5db3b36 100644
--- a/src/components/List/utils.ts
+++ b/src/components/List/utils.ts
@@ -1,7 +1,15 @@
-import { StyleSheet } from 'react-native';
-import type { ColorValue, StyleProp, TextProps, ViewStyle } from 'react-native';
-
-import type { InternalTheme, ThemeProp } from '../../theme/types';
+import * as React from 'react';
+import { Platform, StyleSheet } from 'react-native';
+import type {
+ ColorValue,
+ StyleProp,
+ TextLayoutEvent,
+ TextProps,
+ ViewStyle,
+} from 'react-native';
+
+import { ListTokens } from './tokens';
+import type { ColorRole, InternalTheme, ThemeProp } from '../../theme/types';
type Description =
| React.ReactNode
@@ -26,82 +34,158 @@ export type Style = {
alignSelf?: 'flex-start' | 'center';
};
-const stylesV3Left = {
- marginRight: 0,
- marginLeft: 16,
-};
-
-const stylesV3Right = {
- marginLeft: 16,
-};
-
-export const getLeftStyles = (
+export const getAccessoryStyles = (
alignToTop: boolean,
description: Description
-) => {
- const stylesV3: Style = {
- ...stylesV3Left,
+): Style => {
+ const style: Style = {
+ marginLeft: ListTokens.leadingSpace,
+ marginRight: 0,
alignSelf: alignToTop ? 'flex-start' : 'center',
};
- if (!description) {
- return {
- ...styles.iconMarginLeft,
- ...styles.marginVerticalNone,
- ...stylesV3,
- };
- }
-
- return {
- ...styles.iconMarginLeft,
- ...stylesV3,
- };
+ return description ? style : { ...style, marginVertical: 0 };
};
-export const getRightStyles = (
- alignToTop: boolean,
- description: Description
-) => {
- const stylesV3: Style = {
- ...stylesV3Right,
- alignSelf: alignToTop ? 'flex-start' : 'center',
- };
+/**
+ * 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,
+});
- if (!description) {
- return {
- ...styles.iconMarginRight,
- ...styles.marginVerticalNone,
- ...stylesV3,
- };
- }
+/**
+ * Text and icon colors for a `List.Item` or `List.Accordion` row. Disabled
+ * wins over selected, as in the MD3 tokens.
+ */
+export const getListColors = ({
+ theme,
+ selected,
+ disabled,
+}: {
+ theme: InternalTheme;
+ selected?: boolean;
+ disabled?: boolean;
+}): {
+ titleColor: ColorValue;
+ descriptionColor: ColorValue;
+ leadingIconColor: ColorValue;
+ trailingIconColor: ColorValue;
+ expandIconColor: ColorValue;
+} => {
+ const pick = (role: ColorRole) => {
+ if (disabled) {
+ return theme.colors[ListTokens.disabledContentColor];
+ }
+
+ return theme.colors[selected ? ListTokens.selectedContentColor : role];
+ };
return {
- ...styles.iconMarginRight,
- ...stylesV3,
+ titleColor: pick(ListTokens.headlineColor),
+ descriptionColor: pick(ListTokens.supportingTextColor),
+ leadingIconColor: pick(ListTokens.leadingIconColor),
+ trailingIconColor: pick(ListTokens.trailingIconColor),
+ expandIconColor: pick(ListTokens.expandTrailingIconColor),
};
};
-const styles = StyleSheet.create({
- marginVerticalNone: { marginVertical: 0 },
- iconMarginLeft: { marginLeft: 0, marginRight: 16 },
- iconMarginRight: { marginRight: 0 },
-});
-
-export const getAccordionColors = ({
+/**
+ * Background of a selected row. A selected, disabled row gets an `onSurface`
+ * layer at 38% opacity instead, which `ListSelectedDisabledLayer` draws.
+ */
+export const getSelectedContainerColor = ({
theme,
- isExpanded,
+ selected,
+ disabled,
}: {
theme: InternalTheme;
- isExpanded?: boolean;
-}): { descriptionColor: ColorValue; titleTextColor: ColorValue } => {
- const titleColor = theme.colors.onSurface;
+ selected?: boolean;
+ disabled?: boolean;
+}): ColorValue | undefined =>
+ selected && !disabled
+ ? theme.colors[ListTokens.selectedContainerColor]
+ : undefined;
+
+/**
+ * The selected state for screen readers. On native, `aria-selected` is
+ * announced as "selected". On web, `aria-selected` is not valid on
+ * `role="button"` and goes unannounced, so a button row uses `aria-pressed`,
+ * as `IconButton` does. React Native's types have no `aria-pressed`.
+ */
+export const getSelectedStateProps = ({
+ selected,
+ role,
+}: {
+ selected?: boolean;
+ role?: string;
+}): { 'aria-selected'?: boolean } | { 'aria-pressed': boolean } => {
+ if (selected === undefined) {
+ return {};
+ }
- const descriptionColor = theme.colors.onSurfaceVariant;
+ return Platform.OS === 'web' && role === 'button'
+ ? { 'aria-pressed': selected }
+ : { 'aria-selected': selected };
+};
- const titleTextColor = isExpanded ? theme.colors?.primary : titleColor;
+/**
+ * Tracks whether the description wraps to more lines, which changes the
+ * row's vertical padding and where its leading and trailing elements sit.
+ */
+export const useListRow = () => {
+ const [isDescriptionMultiline, setIsDescriptionMultiline] =
+ React.useState(false);
- return {
- descriptionColor,
- titleTextColor,
+ const onDescriptionTextLayout = (event: TextLayoutEvent) => {
+ setIsDescriptionMultiline(event.nativeEvent.lines.length >= 2);
};
+
+ const rowContext = React.useMemo(
+ () => ({
+ verticalPadding: isDescriptionMultiline
+ ? ListTokens.threeLineVerticalPadding
+ : ListTokens.verticalPadding,
+ }),
+ [isDescriptionMultiline]
+ );
+
+ return { isDescriptionMultiline, onDescriptionTextLayout, rowContext };
};
+
+export const getRowContainerStyles = (
+ hasDescription: boolean,
+ isDescriptionMultiline: boolean
+) => [
+ rowStyles.container,
+ hasDescription ? rowStyles.containerTwoLine : rowStyles.containerOneLine,
+ isDescriptionMultiline && rowStyles.containerThreeLine,
+];
+
+/**
+ * Fades the content of a disabled row: text, icons and custom elements.
+ */
+export const getRowContentStyle = (disabled?: boolean) =>
+ disabled ? rowStyles.disabledContent : null;
+
+const rowStyles = StyleSheet.create({
+ container: {
+ paddingVertical: ListTokens.verticalPadding,
+ paddingRight: ListTokens.trailingSpace,
+ justifyContent: 'center',
+ },
+ containerOneLine: {
+ minHeight: ListTokens.oneLineContainerHeight,
+ },
+ containerTwoLine: {
+ minHeight: ListTokens.twoLineContainerHeight,
+ },
+ containerThreeLine: {
+ paddingVertical: ListTokens.threeLineVerticalPadding,
+ },
+ disabledContent: {
+ opacity: ListTokens.disabledContentOpacity,
+ },
+});
diff --git a/src/components/__tests__/ListAccordion.test.tsx b/src/components/__tests__/ListAccordion.test.tsx
index 4d594e7bd0..385d10cc45 100644
--- a/src/components/__tests__/ListAccordion.test.tsx
+++ b/src/components/__tests__/ListAccordion.test.tsx
@@ -1,15 +1,18 @@
-import { StyleSheet, View } from 'react-native';
+import { Platform, StyleSheet, View } from 'react-native';
-import { describe, expect, it } from '@jest/globals';
+import { afterEach, describe, expect, it, jest } from '@jest/globals';
-import { 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';
import ListAccordionGroup from '../List/ListAccordionGroup';
import ListIcon from '../List/ListIcon';
import ListItem from '../List/ListItem';
-import { getAccordionColors } from '../List/utils';
+
+afterEach(() => {
+ jest.restoreAllMocks();
+});
const styles = StyleSheet.create({
coloring: {
@@ -122,6 +125,73 @@ 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();
+});
+
+it('clips the content only while it animates', async () => {
+ await render(
+
+
+
+ );
+
+ await userEvent.press(screen.getByText('Accordion item 1'));
+
+ // The child sits in a measuring view inside the animated wrapper
+ const getWrapper = () => screen.getByTestId('accordion-child').parent?.parent;
+
+ expect(getWrapper()).toHaveStyle({ overflow: 'hidden' });
+
+ await act(() => {
+ jest.runAllTimers();
+ });
+
+ expect(getWrapper()).not.toHaveStyle({ overflow: 'hidden' });
+});
+
describe('ListAccordion', () => {
it('should not throw an error when id={0}', async () => {
const ListAccordionTest = () => (
@@ -164,39 +234,203 @@ 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.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: LightTheme.colors.onSurface,
});
});
-});
-describe('getAccordionColors - title text color', () => {
- it('should return theme color, for theme version 3', () => {
- expect(
- getAccordionColors({
- theme: LightTheme,
- })
- ).toMatchObject({
- titleTextColor: LightTheme.colors.onSurface,
+ it('hits the container heights without measuring the description', async () => {
+ await render(
+
+
+
+ );
+
+ expect(screen.getByTestId('list-accordion')).toHaveStyle({
+ minHeight: 56,
+ paddingVertical: 8,
});
});
- it('should return primary color if it is expanded', () => {
+ it('keeps the two line container height once a description is present', async () => {
+ await render(
+
+
+
+ );
+
+ expect(screen.getByTestId('list-accordion')).toHaveStyle({
+ minHeight: 72,
+ paddingVertical: 8,
+ });
+
+ await fireEvent(
+ screen.getByText('Describes the expandable list item'),
+ 'textLayout',
+ { nativeEvent: { lines: [{}, {}] } }
+ );
+
+ expect(screen.getByTestId('list-accordion')).toHaveStyle({
+ minHeight: 72,
+ paddingVertical: 12,
+ });
+ });
+
+ it('uses the expand token for the chevron', async () => {
+ await render(
+
+
+
+ );
+
expect(
- getAccordionColors({
- theme: LightTheme,
- isExpanded: true,
- })
- ).toMatchObject({
- titleTextColor: LightTheme.colors?.primary,
+ screen.getByText('chevron-down', { includeHiddenElements: true })
+ ).toHaveStyle({
+ color: LightTheme.colors.onSurface,
});
});
+
+ 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,
+ });
+ });
+
+ it('renders a selected accordion on the secondary container', async () => {
+ await render(
+
+
+
+ );
+
+ expect(screen.getByText('Accordion item 1')).toHaveStyle({
+ color: LightTheme.colors.onSecondaryContainer,
+ });
+ expect(screen.getByText('Supporting')).toHaveStyle({
+ color: LightTheme.colors.onSecondaryContainer,
+ });
+ });
+
+ // The name is a regex because the icon mock renders the glyph name as text
+ it('announces the expanded state to screen readers', async () => {
+ await render(
+
+
+
+ );
+
+ const header = screen.getByRole('button', { name: /^Accordion item 1/ });
+
+ expect(header).toBeCollapsed();
+
+ await userEvent.press(header);
+
+ expect(
+ screen.getByRole('button', { name: /^Accordion item 1/ })
+ ).toBeExpanded();
+ });
+
+ it('announces a selected accordion to screen readers', async () => {
+ await render(
+
+
+
+ );
+
+ expect(
+ screen.getByRole('button', { name: /^Accordion item 1/ })
+ ).toBeSelected();
+ });
+
+ it('announces a selected accordion with aria-pressed on web', async () => {
+ jest.replaceProperty(Platform, 'OS', 'web');
+ await render(
+
+
+
+ );
+
+ const header = screen.getByRole('button', { name: /^Accordion item 1/ });
+
+ expect(header).toHaveProp('aria-pressed', true);
+ expect(header).not.toBeSelected();
+ });
+
+ it('renders a disabled accordion header in onSurface at 38% opacity', async () => {
+ await render(
+ }
+ selected
+ disabled
+ >
+
+
+ );
+
+ for (const text of ['Accordion item 1', 'Supporting']) {
+ expect(screen.getByText(text)).toHaveStyle({
+ color: LightTheme.colors.onSurface,
+ });
+ }
+ for (const icon of ['folder', 'chevron-down']) {
+ expect(
+ screen.getByText(icon, { includeHiddenElements: true })
+ ).toHaveStyle({ color: LightTheme.colors.onSurface });
+ }
+ // The name also holds the glyph name the icon mock renders
+ expect(
+ screen.getByRole('button', { name: /Accordion item 1/ }).children[0]
+ ).toHaveStyle({ opacity: 0.38 });
+ });
+
+ it('does not expand a disabled accordion and announces it as disabled', async () => {
+ const onPress = jest.fn();
+ await render(
+
+
+
+ );
+
+ const header = screen.getByRole('button', { name: /^Accordion item 1/ });
+
+ expect(header).toBeDisabled();
+
+ await userEvent.press(header);
+
+ expect(onPress).not.toHaveBeenCalled();
+ expect(
+ screen.getByRole('button', { name: /^Accordion item 1/ })
+ ).toBeCollapsed();
+ expect(screen.queryByText('List item 1')).not.toBeOnTheScreen();
+ });
});
diff --git a/src/components/__tests__/ListItem.test.tsx b/src/components/__tests__/ListItem.test.tsx
index 98e6e0f0fe..c03e26615b 100644
--- a/src/components/__tests__/ListItem.test.tsx
+++ b/src/components/__tests__/ListItem.test.tsx
@@ -2,14 +2,16 @@ import type { GestureResponderEvent } from 'react-native';
import { Platform, StyleSheet } from 'react-native';
import { Text, View } from 'react-native';
-import { expect, it, jest } from '@jest/globals';
+import { afterEach, describe, 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 { LightTheme } from '../../theme/schemes';
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({
@@ -26,6 +28,10 @@ const styles = StyleSheet.create({
const testID = 'list-item';
+afterEach(() => {
+ jest.restoreAllMocks();
+});
+
it('renders list item with title and description', async () => {
const tree = (
await render(
@@ -147,7 +153,7 @@ it('renders with a description with typeof number', async () => {
});
it('calling onPress on ListItem right component', async () => {
- Platform.OS = 'web';
+ jest.replaceProperty(Platform, 'OS', 'web');
const onPress = jest.fn<(event: GestureResponderEvent) => void>();
await render(
@@ -177,3 +183,386 @@ it('renders list item with custom content style', async () => {
expect(toJSON()).toMatchSnapshot();
});
+
+it('hits the one line container height without measuring the description', async () => {
+ await render();
+
+ expect(screen.getByTestId(testID)).toHaveStyle({
+ minHeight: 56,
+ paddingVertical: 8,
+ });
+});
+
+it('hits the two and three line container heights without measuring', async () => {
+ await render(
+
+ );
+
+ expect(screen.getByTestId(testID)).toHaveStyle({
+ minHeight: 72,
+ paddingVertical: 8,
+ });
+
+ await fireEvent(screen.getByText('Item description'), 'textLayout', {
+ nativeEvent: { lines: [{}, {}] },
+ });
+
+ expect(screen.getByTestId(testID)).toHaveStyle({
+ minHeight: 72,
+ paddingVertical: 12,
+ });
+});
+
+// The row is 88dp tall: 2 * padding + 2 * margin + the 64dp thumbnail.
+it.each([
+ ['one line', undefined, false, 8, 4],
+ ['two line', 'Item description', false, 8, 4],
+ ['three line', 'Item description', true, 12, 0],
+])(
+ 'makes a %s row with a video thumbnail 88dp tall',
+ async (_label, description, wrapsDescription, padding, margin) => {
+ await render(
+
+ }
+ testID={testID}
+ />
+ );
+
+ if (wrapsDescription) {
+ await fireEvent(screen.getByText('Item description'), 'textLayout', {
+ nativeEvent: { lines: [{}, {}] },
+ });
+ }
+
+ expect(screen.getByTestId(testID)).toHaveStyle({
+ 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(
+ }
+ trailing={}
+ testID={testID}
+ />
+ );
+
+ expect(
+ screen.getByText('folder', { includeHiddenElements: true })
+ ).toHaveStyle({ color: LightTheme.colors.onSurfaceVariant });
+ expect(
+ screen.getByText('chevron-right', { includeHiddenElements: true })
+ ).toHaveStyle({ color: LightTheme.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(
+ }
+ 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 () => {
+ await render(
+
+ );
+
+ expect(screen.getByText('First Item')).toHaveStyle({ fontSize: 99 });
+ expect(screen.getByText('Item description')).toHaveStyle({ fontSize: 77 });
+});
+
+it.each([
+ [
+ 'an unselected item on surface colors',
+ false,
+ undefined,
+ LightTheme.colors.onSurface,
+ LightTheme.colors.onSurfaceVariant,
+ ],
+ [
+ 'a selected item on the secondary container',
+ true,
+ LightTheme.colors.secondaryContainer,
+ LightTheme.colors.onSecondaryContainer,
+ LightTheme.colors.onSecondaryContainer,
+ ],
+])(
+ '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,
+ });
+ }
+);
+
+it('announces a pressable item as a button', async () => {
+ await render( {}} />);
+
+ expect(screen.getByRole('button', { name: 'First Item' })).toBeOnTheScreen();
+});
+
+it('does not give an item without onPress the button role', async () => {
+ await render();
+
+ expect(screen.queryByRole('button')).not.toBeOnTheScreen();
+});
+
+it('announces a selected item to screen readers', async () => {
+ await render( {}} selected />);
+
+ expect(screen.getByRole('button', { name: 'First Item' })).toBeSelected();
+});
+
+it('lets a caller override the role and the selected state', async () => {
+ await render(
+ {}}
+ selected
+ role="link"
+ aria-selected={false}
+ />
+ );
+
+ expect(screen.getByRole('link', { name: 'First Item' })).not.toBeSelected();
+});
+
+it('puts a video thumbnail in the leading slot flush with the start edge', async () => {
+ await render(
+
+ }
+ />
+ );
+
+ // The slot adds 16dp of leading space and the video takes it back
+ expect(screen.getByTestId('video-thumbnail').parent).toHaveStyle({
+ marginLeft: 16,
+ });
+ expect(screen.getByTestId('video-thumbnail')).toHaveStyle({
+ marginLeft: -16,
+ });
+});
+
+it('keeps a video thumbnail from the left render prop flush with the start edge', async () => {
+ await render(
+ (
+
+ )}
+ />
+ );
+
+ expect(screen.getByTestId('video-thumbnail')).toHaveStyle({ marginLeft: 0 });
+});
+
+it.each([
+ ['a disabled item', false],
+ ['a selected, disabled item', true],
+])(
+ 'renders the content of %s in onSurface at 38%% opacity',
+ async (_label, selected) => {
+ await render(
+ }
+ trailing={}
+ selected={selected}
+ disabled
+ testID={testID}
+ />
+ );
+
+ expect(screen.getByText('First Item')).toHaveStyle({
+ color: LightTheme.colors.onSurface,
+ });
+ expect(screen.getByText('Item description')).toHaveStyle({
+ color: LightTheme.colors.onSurface,
+ });
+ expect(
+ screen.getByText('folder', { includeHiddenElements: true })
+ ).toHaveStyle({ color: LightTheme.colors.onSurface });
+ // The row that holds the slots, title and description
+ expect(screen.getByTestId('trailing').parent?.parent).toHaveStyle({
+ opacity: 0.38,
+ });
+ }
+);
+
+it('does not fade the content of an enabled item', async () => {
+ await render(
+ } />
+ );
+
+ expect(screen.getByTestId('trailing').parent?.parent).not.toHaveStyle({
+ opacity: 0.38,
+ });
+});
+
+it('puts a selected, disabled item on an onSurface layer at 38% opacity', async () => {
+ await render(
+
+ );
+
+ const item = screen.getByTestId(testID);
+
+ expect(item).toHaveStyle({ backgroundColor: undefined });
+ expect(item.children[0]).toHaveStyle({
+ backgroundColor: LightTheme.colors.onSurface,
+ opacity: 0.38,
+ });
+});
+
+it('does not call onPress on a disabled item and announces it as disabled', async () => {
+ const onPress = jest.fn<(event: GestureResponderEvent) => void>();
+ await render();
+
+ const item = screen.getByRole('button', { name: 'First Item' });
+
+ expect(item).toBeDisabled();
+
+ await userEvent.press(item);
+
+ expect(onPress).not.toHaveBeenCalled();
+});
+
+describe('selected state on web', () => {
+ it('announces a selected button item with aria-pressed, which fits a button', async () => {
+ jest.replaceProperty(Platform, 'OS', 'web');
+ await render( {}} selected />);
+
+ const item = screen.getByRole('button', { name: 'First Item' });
+
+ expect(item).toHaveProp('aria-pressed', true);
+ expect(item).not.toBeSelected();
+ });
+
+ it('keeps aria-selected when a caller gives the item another role', async () => {
+ jest.replaceProperty(Platform, 'OS', 'web');
+ await render(
+ {}} selected role="option" />
+ );
+
+ const item = screen.getByRole('option', { name: 'First Item' });
+
+ // React Native moves `aria-selected` into `accessibilityState`
+ expect(item).toBeSelected();
+ expect(item).not.toHaveProp('aria-pressed');
+ });
+});
diff --git a/src/components/__tests__/ListUtils.test.tsx b/src/components/__tests__/ListUtils.test.tsx
index b733f832d0..1ffd2e4231 100644
--- a/src/components/__tests__/ListUtils.test.tsx
+++ b/src/components/__tests__/ListUtils.test.tsx
@@ -1,55 +1,64 @@
-import { StyleSheet } from 'react-native';
-
import { expect, it } from '@jest/globals';
-import { getLeftStyles, getRightStyles } from '../List/utils';
+import { LightTheme } from '../../theme/schemes';
+import { getAccessoryStyles, getListColors } from '../List/utils';
import Text from '../Typography/Text';
-const styles = StyleSheet.create({
- leftItemV3: {
- marginLeft: 16,
- marginRight: 0,
- alignSelf: 'center',
- },
- rightItemV3: {
- marginLeft: 16,
- marginRight: 0,
- alignSelf: 'center',
- },
-});
+const accessoryStyle = {
+ marginLeft: 16,
+ marginRight: 0,
+ alignSelf: 'center',
+};
const description = Test;
-/**
- * ********************** getLeftStyles ********************** *
- */
-
-it('returns styles for left item without description', () => {
- const style = getLeftStyles(false, null);
- expect(style).toStrictEqual({ ...styles.leftItemV3, marginVertical: 0 });
+it('returns accessory styles without description', () => {
+ const style = getAccessoryStyles(false, null);
+ expect(style).toStrictEqual({ ...accessoryStyle, marginVertical: 0 });
});
-it('returns styles for left item w/ description', () => {
- const style = getLeftStyles(true, description);
+it('returns accessory styles aligned to the top for a multiline description', () => {
+ const style = getAccessoryStyles(true, description);
expect(style).toStrictEqual({
- ...styles.leftItemV3,
+ ...accessoryStyle,
alignSelf: 'flex-start',
});
});
-/**
- * ********************** getRightStyles ********************** *
- */
-
-it('returns styles for right item without description', () => {
- const style = getRightStyles(false, null);
- expect(style).toStrictEqual({ ...styles.rightItemV3, marginVertical: 0 });
-});
-
-it('returns styles for right item w/ description', () => {
- const style = getRightStyles(true, description);
- expect(style).toStrictEqual({
- ...styles.rightItemV3,
- alignSelf: 'flex-start',
- });
+it.each([
+ [
+ 'an enabled row',
+ {},
+ {
+ titleColor: LightTheme.colors.onSurface,
+ descriptionColor: LightTheme.colors.onSurfaceVariant,
+ leadingIconColor: LightTheme.colors.onSurfaceVariant,
+ trailingIconColor: LightTheme.colors.onSurfaceVariant,
+ expandIconColor: LightTheme.colors.onSurface,
+ },
+ ],
+ [
+ 'a selected row',
+ { selected: true },
+ {
+ titleColor: LightTheme.colors.onSecondaryContainer,
+ descriptionColor: LightTheme.colors.onSecondaryContainer,
+ leadingIconColor: LightTheme.colors.onSecondaryContainer,
+ trailingIconColor: LightTheme.colors.onSecondaryContainer,
+ expandIconColor: LightTheme.colors.onSecondaryContainer,
+ },
+ ],
+ [
+ 'a selected, disabled row',
+ { selected: true, disabled: true },
+ {
+ titleColor: LightTheme.colors.onSurface,
+ descriptionColor: LightTheme.colors.onSurface,
+ leadingIconColor: LightTheme.colors.onSurface,
+ trailingIconColor: LightTheme.colors.onSurface,
+ expandIconColor: LightTheme.colors.onSurface,
+ },
+ ],
+])('returns the colors for %s', (_label, state, colors) => {
+ expect(getListColors({ theme: LightTheme, ...state })).toStrictEqual(colors);
});
diff --git a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap
index 5e73775c72..a561ab7c21 100644
--- a/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap
+++ b/src/components/__tests__/__snapshots__/ListAccordion.test.tsx.snap
@@ -46,10 +46,17 @@ exports[`renders expanded accordion 1`] = `
"overflow": "hidden",
},
[
- {
- "paddingRight": 24,
- "paddingVertical": 8,
- },
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
undefined,
],
]
@@ -61,8 +68,8 @@ exports[`renders expanded accordion 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
},
+ null,
undefined,
]
}
@@ -91,21 +98,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,121 +123,163 @@ exports[`renders expanded accordion 1`] = `
-
- chevron-up
-
+
+ chevron-down
+
+
-
+
- List item 1
-
+ ]
+ }
+ >
+
+ List item 1
+
+
+
@@ -282,10 +332,17 @@ exports[`renders list accordion with children 1`] = `
"overflow": "hidden",
},
[
- {
- "paddingRight": 24,
- "paddingVertical": 8,
- },
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
undefined,
],
]
@@ -297,8 +354,8 @@ exports[`renders list accordion with children 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
},
+ null,
undefined,
]
}
@@ -374,21 +431,22 @@ exports[`renders list accordion with children 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,
+ ],
],
]
}
@@ -398,44 +456,56 @@ exports[`renders list accordion with children 1`] = `
-
- chevron-down
-
+
+ chevron-down
+
+
@@ -489,10 +559,17 @@ exports[`renders list accordion with custom title and description styles 1`] = `
"overflow": "hidden",
},
[
- {
- "paddingRight": 24,
- "paddingVertical": 8,
- },
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
undefined,
],
]
@@ -504,8 +581,8 @@ exports[`renders list accordion with custom title and description styles 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
},
+ null,
undefined,
]
}
@@ -534,23 +611,24 @@ exports[`renders list accordion with custom title and description styles 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)",
- },
- {
- "color": "#f44336",
- },
+ [
+ {
+ "color": "rgba(29, 27, 32, 1)",
+ },
+ {
+ "color": "#f44336",
+ },
+ ],
],
]
}
@@ -568,23 +646,24 @@ exports[`renders list accordion with custom title and description styles 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)",
- },
- {
- "color": "#f44336",
- },
+ [
+ {
+ "color": "rgba(73, 69, 79, 1)",
+ },
+ {
+ "color": "#f44336",
+ },
+ ],
],
]
}
@@ -594,48 +673,56 @@ exports[`renders list accordion with custom title and description styles 1`] = `
-
- chevron-down
-
+
+ chevron-down
+
+
@@ -689,10 +776,17 @@ exports[`renders list accordion with left items 1`] = `
"overflow": "hidden",
},
[
- {
- "paddingRight": 24,
- "paddingVertical": 8,
- },
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
undefined,
],
]
@@ -704,8 +798,8 @@ exports[`renders list accordion with left items 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
},
+ null,
undefined,
]
}
@@ -781,21 +875,22 @@ exports[`renders list accordion with left items 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,
+ ],
],
]
}
@@ -805,44 +900,56 @@ exports[`renders list accordion with left items 1`] = `
-
- chevron-down
-
+
+ chevron-down
+
+
@@ -896,10 +1003,17 @@ exports[`renders multiline list accordion 1`] = `
"overflow": "hidden",
},
[
- {
- "paddingRight": 24,
- "paddingVertical": 8,
- },
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
undefined,
],
]
@@ -911,8 +1025,8 @@ exports[`renders multiline list accordion 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
},
+ null,
undefined,
]
}
@@ -941,21 +1055,22 @@ exports[`renders multiline list 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(29, 27, 32, 1)",
- },
- undefined,
+ [
+ {
+ "color": "rgba(29, 27, 32, 1)",
+ },
+ undefined,
+ ],
],
]
}
@@ -973,21 +1088,22 @@ exports[`renders multiline list accordion 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,
+ ],
],
]
}
@@ -997,48 +1113,56 @@ exports[`renders multiline list accordion 1`] = `
-
- chevron-down
-
+
+ chevron-down
+
+
diff --git a/src/components/__tests__/__snapshots__/ListImage.test.tsx.snap b/src/components/__tests__/__snapshots__/ListImage.test.tsx.snap
index 927779644c..08473d8ed5 100644
--- a/src/components/__tests__/__snapshots__/ListImage.test.tsx.snap
+++ b/src/components/__tests__/__snapshots__/ListImage.test.tsx.snap
@@ -36,6 +36,10 @@ exports[`renders ListImage with \`video\` variant 1`] = `
"marginLeft": 0,
"width": 114,
},
+ {
+ "marginVertical": 4,
+ },
+ false,
]
}
/>
diff --git a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap
index d4195e806c..f83fda793b 100644
--- a/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap
+++ b/src/components/__tests__/__snapshots__/ListItem.test.tsx.snap
@@ -7,9 +7,20 @@ exports[`renders list item with custom content style 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -22,9 +33,9 @@ exports[`renders list item with custom content style 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -56,21 +67,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 +100,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,
+ ],
],
]
}
@@ -121,9 +134,20 @@ exports[`renders list item with custom description 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -136,9 +160,9 @@ exports[`renders list item with custom description 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -168,21 +192,22 @@ exports[`renders list item with custom description 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,
+ ],
],
]
}
@@ -482,9 +507,20 @@ exports[`renders list item with custom title and description styles 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -497,9 +533,9 @@ exports[`renders list item with custom title and description styles 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -529,23 +565,24 @@ exports[`renders list item with custom title and description styles 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)",
- },
- {
- "fontSize": 20,
- },
+ [
+ {
+ "color": "rgba(29, 27, 32, 1)",
+ },
+ {
+ "fontSize": 20,
+ },
+ ],
],
]
}
@@ -563,23 +600,24 @@ exports[`renders list item with custom title and description styles 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)",
- },
- {
- "color": "#f44336",
- },
+ [
+ {
+ "color": "rgba(73, 69, 79, 1)",
+ },
+ {
+ "color": "#f44336",
+ },
+ ],
],
]
}
@@ -598,9 +636,20 @@ exports[`renders list item with left and right items 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -613,9 +662,9 @@ exports[`renders list item with left and right items 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -648,21 +697,22 @@ exports[`renders list item with left and right items 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,
+ ],
],
]
}
@@ -680,21 +730,22 @@ exports[`renders list item with left and right items 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,
+ ],
],
]
}
@@ -759,9 +810,20 @@ exports[`renders list item with left item 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -774,9 +836,9 @@ exports[`renders list item with left item 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -853,21 +915,22 @@ exports[`renders list item with left item 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,
+ ],
],
]
}
@@ -886,9 +949,20 @@ exports[`renders list item with right item 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -901,9 +975,9 @@ exports[`renders list item with right item 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -933,21 +1007,22 @@ exports[`renders list item with right item 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,
+ ],
],
]
}
@@ -969,9 +1044,20 @@ exports[`renders list item with title and description 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -984,9 +1070,9 @@ exports[`renders list item with title and description 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -1016,21 +1102,22 @@ exports[`renders list item with title and description 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,
+ ],
],
]
}
@@ -1048,21 +1135,22 @@ exports[`renders list item with title and description 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,
+ ],
],
]
}
@@ -1081,9 +1169,20 @@ exports[`renders with a description with typeof number 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 72,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -1096,9 +1195,9 @@ exports[`renders with a description with typeof number 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -1128,23 +1227,24 @@ exports[`renders with a description with typeof number 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)",
- },
- {
- "fontSize": 20,
- },
+ [
+ {
+ "color": "rgba(29, 27, 32, 1)",
+ },
+ {
+ "fontSize": 20,
+ },
+ ],
],
]
}
@@ -1162,23 +1262,24 @@ exports[`renders with a description with typeof number 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)",
- },
- {
- "color": "#f44336",
- },
+ [
+ {
+ "color": "rgba(73, 69, 79, 1)",
+ },
+ {
+ "color": "#f44336",
+ },
+ ],
],
]
}
diff --git a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap
index 8933cc1b95..45fa3496e9 100644
--- a/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap
+++ b/src/components/__tests__/__snapshots__/ListSection.test.tsx.snap
@@ -456,9 +456,20 @@ exports[`renders list section with custom title style 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -471,9 +482,9 @@ exports[`renders list section with custom title style 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -550,21 +561,22 @@ exports[`renders list section with custom title 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,
+ ],
],
]
}
@@ -580,9 +592,20 @@ exports[`renders list section with custom title style 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -595,9 +618,9 @@ exports[`renders list section with custom title style 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -674,21 +697,22 @@ exports[`renders list section with custom title 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,
+ ],
],
]
}
@@ -1155,9 +1179,20 @@ exports[`renders list section with subheader 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -1170,9 +1205,9 @@ exports[`renders list section with subheader 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -1249,21 +1284,22 @@ exports[`renders list section with subheader 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,
+ ],
],
]
}
@@ -1279,9 +1315,20 @@ exports[`renders list section with subheader 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -1294,9 +1341,9 @@ exports[`renders list section with subheader 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -1373,21 +1420,22 @@ exports[`renders list section with subheader 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,
+ ],
],
]
}
@@ -1814,9 +1862,20 @@ exports[`renders list section without subheader 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -1829,9 +1888,9 @@ exports[`renders list section without subheader 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -1908,21 +1967,22 @@ exports[`renders list section without subheader 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,
+ ],
],
]
}
@@ -1938,9 +1998,20 @@ exports[`renders list section without subheader 1`] = `
[
false,
[
+ [
+ {
+ "justifyContent": "center",
+ "paddingRight": 16,
+ "paddingVertical": 8,
+ },
+ {
+ "minHeight": 56,
+ },
+ false,
+ ],
+ false,
{
- "paddingRight": 24,
- "paddingVertical": 8,
+ "backgroundColor": undefined,
},
undefined,
],
@@ -1953,9 +2024,9 @@ exports[`renders list section without subheader 1`] = `
[
{
"flexDirection": "row",
- "marginVertical": 6,
"width": "100%",
},
+ null,
undefined,
]
}
@@ -2032,21 +2103,22 @@ exports[`renders list section without subheader 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,
+ ],
],
]
}