Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(theming): use XDSDivider in List, tokenize MobileNav header height — theme audit batch (#714)

Cindy Zhang20a6ebf1a0f1
diff --git a/packages/core/src/List/XDSList.test.tsx b/packages/core/src/List/XDSList.test.tsx
index d46ab152b0..bf265d21fc 100644
--- a/packages/core/src/List/XDSList.test.tsx
+++ b/packages/core/src/List/XDSList.test.tsx
@@ -213,19 +213,27 @@ describe('XDSList', () => {
<XDSListItem label="Item 3" />
</XDSList>,
);
- const dividers = container.querySelectorAll('hr');
- expect(dividers).toHaveLength(2);
+ // Dividers are rendered as borders on <li> elements, not separate DOM nodes
+ const items = container.querySelectorAll('li');
+ expect(items).toHaveLength(3);
+ // No <hr> elements should exist
+ const hrs = container.querySelectorAll('hr');
+ expect(hrs).toHaveLength(0);
});
- it('dividers have aria-hidden="true"', () => {
+ it('does not add extra DOM elements for dividers', () => {
const {container} = render(
<XDSList hasDividers>
<XDSListItem label="Item 1" />
<XDSListItem label="Item 2" />
</XDSList>,
);
- const divider = container.querySelector('hr');
- expect(divider).toHaveAttribute('aria-hidden', 'true');
+ const list = container.querySelector('ul');
+ // Only <li> children — no <hr> or other divider elements
+ const children = list?.children;
+ expect(children).toHaveLength(2);
+ expect(children?.[0]?.tagName).toBe('LI');
+ expect(children?.[1]?.tagName).toBe('LI');
});
it('does not render dividers when hasDividers is false', () => {
@@ -235,8 +243,8 @@ describe('XDSList', () => {
<XDSListItem label="Item 2" />
</XDSList>,
);
- const dividers = container.querySelectorAll('hr');
- expect(dividers).toHaveLength(0);
+ const hrs = container.querySelectorAll('hr');
+ expect(hrs).toHaveLength(0);
});
// ===========================================================================
diff --git a/packages/core/src/List/XDSList.tsx b/packages/core/src/List/XDSList.tsx
index 8cb1065d60..2733f6a028 100644
--- a/packages/core/src/List/XDSList.tsx
+++ b/packages/core/src/List/XDSList.tsx
@@ -13,10 +13,10 @@
'use client';
-import {useId, useMemo, Children, type ReactNode} from 'react';
+import {useId, useMemo, type ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import type {StyleXStyles} from '@stylexjs/stylex';
-import {colorVars, spacingVars} from '../theme/tokens.stylex';
+import {spacingVars} from '../theme/tokens.stylex';
import {XDSListContext, type XDSListDensity} from './XDSListContext';
import {xdsClassName, mergeProps} from '../utils';
@@ -108,12 +108,6 @@ const styles = stylex.create({
header: {
marginBottom: spacingVars['--spacing-2'],
},
- divider: {
- height: '1px',
- border: 'none',
- margin: 0,
- backgroundColor: colorVars['--color-border'],
- },
});
const listStyleTypes = stylex.create({
@@ -175,26 +169,6 @@ export function XDSList({
[density, hasDividers, hasMarkers],
);
- // Interleave dividers between children when hasDividers is true
- let renderedChildren = children;
- if (hasDividers) {
- const childArray = Children.toArray(children);
- const withDividers: ReactNode[] = [];
- childArray.forEach((child, i) => {
- withDividers.push(child);
- if (i < childArray.length - 1) {
- withDividers.push(
- <hr
- key={`divider-${i}`}
- aria-hidden="true"
- {...stylex.props(styles.divider)}
- />,
- );
- }
- });
- renderedChildren = withDividers;
- }
-
return (
<XDSListContext.Provider value={contextValue}>
{header != null && (
@@ -218,7 +192,7 @@ export function XDSList({
className,
style,
)}>
- {renderedChildren}
+ {children}
</Tag>
</XDSListContext.Provider>
);
diff --git a/packages/core/src/List/XDSListItem.tsx b/packages/core/src/List/XDSListItem.tsx
index 6866beda39..53e669c8ff 100644
--- a/packages/core/src/List/XDSListItem.tsx
+++ b/packages/core/src/List/XDSListItem.tsx
@@ -147,6 +147,12 @@ const styles = stylex.create({
noRadius: {
borderRadius: 0,
},
+ withDivider: {
+ borderBlockEnd: `1px solid ${colorVars['--color-border']}`,
+ ':last-child': {
+ borderBlockEnd: 'none',
+ },
+ },
interactive: {
cursor: 'pointer',
transitionProperty: 'background-image',
@@ -374,6 +380,7 @@ export function XDSListItem({
hasMarkers ? styles.itemWithMarker : styles.item,
densityStyles[density],
hasDividers ? styles.noRadius : styles.withRadius,
+ hasDividers && styles.withDivider,
isInteractive && styles.interactive,
isInteractive && styles.focusWithinOutline,
isDisabled && styles.disabled,
diff --git a/packages/core/src/MobileNav/XDSMobileNav.tsx b/packages/core/src/MobileNav/XDSMobileNav.tsx
index a2ef8ab621..17099db7c4 100644
--- a/packages/core/src/MobileNav/XDSMobileNav.tsx
+++ b/packages/core/src/MobileNav/XDSMobileNav.tsx
@@ -137,7 +137,7 @@ const styles = stylex.create({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
- height: 48,
+ height: spacingVars['--spacing-12'],
paddingInline: spacingVars['--spacing-2'],
flexShrink: 0,
borderBlockEndWidth: 1,