Skip to content

refactor: modernize Divider to latest MD3 spec - #5089

Open
mikolajadamowicz wants to merge 3 commits into
callstack:mainfrom
mikolajadamowicz:divider-md3
Open

mikolajadamowicz wants to merge 3 commits into
callstack:mainfrom
mikolajadamowicz:divider-md3

Conversation

@mikolajadamowicz

Copy link
Copy Markdown

Motivation

Divider was drawing a StyleSheet.hairlineWidth line, which is thinner than 1dp on most screens, and the full 1dp line the Material Design 3 spec asks for was only reachable through bold. leftInset set marginLeft, so in RTL the inset stayed on the left instead of moving to the leading edge. MD3 also lists a vertical divider, which we had no way to render.

This is primitive level work for the v6 effort. The consumers (List, Dialog, Drawer, DataTable) pick up the corrected divider in their own tasks.

Changes

  • Thickness: StyleSheet.hairlineWidth → 1dp, applied as height when horizontal and width when vertical
  • Inset: leftInset (marginLeft: 16) → startInset (marginStart: 16), so it follows the writing direction
  • Orientation: new orientation="horizontal" | "vertical". A vertical divider is 1dp wide and uses alignSelf: 'stretch' to take the height of its parent
  • Insets follow the orientation: on a vertical divider startInset insets the top edge and horizontalInset insets the top and bottom edges
  • Accessibility: the divider is aria-hidden by default, so screen readers skip it and it stays out of the focus order. React Native maps that to accessibilityElementsHidden on iOS and importantForAccessibility="no-hide-descendants" on Android. It is spread before ...rest, so <Divider accessible aria-hidden={false} role="separator" /> opts back in

Breaking change

The bold and leftInset props have been removed.

// Before (v5)
<Divider bold />
<Divider leftInset />

// After (v6)
<Divider />
<Divider startInset />

bold existed only to reach 1dp, which is now the default. For the old hairline line, pass style={{ height: StyleSheet.hairlineWidth }}.

The full entry is in docs/6.x/docs/guides/migration.md.

Callsites updated

  • src/components/Searchbar.tsx and src/components/Drawer/DrawerSection.tsx dropped bold, so they render the same as before
  • example/src/Examples/DividerExample.tsx now shows full width, start inset, both side inset and vertical dividers
  • example/src/Examples/FABExample.tsx dropped bold
  • src/components/__tests__/Drawer/__snapshots__/DrawerSection.test.tsx.snap updated

Related issue

N/A

Test plan

  • yarn lint clean
  • yarn typecheck clean, plus tsc --noEmit in example/
  • yarn test 56 suites, 743 passed, including 11 new Divider tests in src/components/__tests__/Divider.test.tsx
  • yarn docs build clean, Divider.mdx and componentDocs6x.json regenerated
  • Example app, Divider screen: full width, start inset, both side inset and vertical sections

To check it by hand, open the example app, go to the Divider screen and compare against main. The line is visibly thicker, and the vertical section is new.

Visual verification

Platform divider
Android (Pixel 9 Pro XL) divider
iOS (iPhone 17 Pro) divider

@JKobrynski JKobrynski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment, we've also got conflicts

Comment thread docs/6.x/docs/guides/migration.md Outdated

## Components

### Divider

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conflicts with main now - #5078 landed a ## General changes section at the same insertion point. Both sides only add text, so keeping both resolves it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebased on main and resolved the conflicts:

  • docs/6.x/docs/guides/migration.md: kept both sections: this PR's new ### Divider entry plus refactor: rework Surface and elevation shadows #5078's ## General changes section, as suggested.
  • docs/6.x/docs/components/Divider.mdx: removed, following main's deletion. main migrated to auto-generated component docs (from JSDoc in source), and the accessibility note this PR added here already lives in Divider.tsx's JSDoc, so nothing was lost.
  • docs/src/data/componentDocs6x.json: removed, also following main's deletion (a generated data file for the old docs system, no longer used).


return (
<View
aria-hidden

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests that look up a divider will stop finding it - aria-hidden keeps it out of getByTestId unless the query passes { includeHiddenElements: true }. Worth a line in the migration guide?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I've added a note in the migration guide. Also fixed latest conflicts.

@JKobrynski JKobrynski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, one minor comment + we've got conflicts

@JKobrynski JKobrynski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@satya164 all yours!

@Doberjohn Doberjohn added this to the 6.0.0 milestone Oct 30, 2026
* horizontal divider, top and bottom on a vertical one.
*/
bold?: boolean;
horizontalInset?: boolean;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MD3 spec doesn't define insets for vertical dividers. The specs table lists insets only as left/right margins (inset 16/0dp, middle-inset 16/16dp), and the guidelines describe vertical dividers without any inset variants.

Compose's VerticalDivider has no inset parameter either, spacing goes through Modifier.padding.

Here startInset becomes marginTop and horizontalInset becomes marginTop/marginBottom on a vertical divider, so <Divider orientation="vertical" horizontalInset /> insets vertically, which the name doesn't suggest.

Two options:

  1. Don't apply startInset/horizontalInset when orientation="vertical" and leave spacing to style, like Compose. I'd prefer this one.
  2. If we want insets on vertical dividers, rename horizontalInset to middleInset to match MD3's naming, so it reads right in both orientations. That's another breaking change, so it needs a migration row and an update in DrawerSection.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for option 1

Comment on lines +76 to +81
isVertical ? styles.vertical : styles.horizontal,
{ backgroundColor: theme.colors.outlineVariant },
startInset &&
(isVertical ? styles.verticalStartInset : styles.startInset),
horizontalInset &&
(isVertical ? styles.verticalInset : styles.horizontalInset),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: isVertical ? … : … is repeated three times here. Grouping the styles by orientation would let us pick the set once:

const s = styles[orientation];

style={[
  s.line,
  { backgroundColor: theme.colors.outlineVariant },
  startInset && s.startInset,
  horizontalInset && s.inset,
  style,
]}

const styles = {
  horizontal: StyleSheet.create({
    line: { height: THICKNESS },
    startInset: { marginStart: INSET },
    inset: { marginStart: INSET, marginEnd: INSET },
  }),
  vertical: StyleSheet.create({
    line: { width: THICKNESS, alignSelf: 'stretch' },
    startInset: { marginTop: INSET },
    inset: { marginTop: INSET, marginBottom: INSET },
  }),
};

@lukewalczak lukewalczak self-assigned this Nov 23, 2026
# Conflicts:
#	docs/6.x/docs/guides/migration.md
#	src/components/Drawer/DrawerSection.tsx
#	src/components/__tests__/Drawer/__snapshots__/DrawerSection.test.tsx.snap

@jacekAtCK jacekAtCK left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we need ! in the PR title since bold and leftInset are gone? also left some comments below.


```diff
- <Divider />
+ <Divider style={{ height: StyleSheet.hairlineWidth }} />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: on a vertical divider the hairline override is width: StyleSheet.hairlineWidth not height.

* horizontal divider, top and bottom on a vertical one.
*/
bold?: boolean;
horizontalInset?: boolean;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for option 1

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants