Skip to main content

Split Button

A split button has two buttons in one row. The leading button does the main action. The trailing button has only an icon, and it opens a menu of related actions. The component follows the Material Design 3 Split Button specification, from MD3 Expressive.

Usage​

Put the SplitButton in the anchor of a controlled Menu. onPress is the main action. expanded and onExpandedChange connect the trailing button to the menu.

import { Menu, PortalHost, SplitButton } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { useState } from 'react'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
const [open, setOpen] = useState(false)

return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Menu
visible={open}
onDismiss={() => setOpen(false)}
align="end"
anchor={
<SplitButton
leadingIcon="content-save-outline"
onPress={() => console.log('Save')}
expanded={open}
onExpandedChange={setOpen}
trailingAccessibilityLabel="More save options"
>
Save
</SplitButton>
}
>
<Menu.Item label="Save as" onPress={() => console.log('Save as')} />
<Menu.Item label="Save all" onPress={() => console.log('Save all')} />
</Menu>
</View>
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

Use the controlled form of the menu (visible and onDismiss). A menu that opens itself hooks the press of its anchor, and for a split button that press is the main action.

align="end" puts the menu below the trailing button.

Variants​

Both buttons take one variant. Each variant has the colors of the same Button variant. Material Design 3 has no text split button.

VariantUse case
filled (default)The most important action on the screen
tonalAn important action that needs less emphasis
elevatedAn action on a surface that needs separation
outlinedA medium-emphasis action
<SplitButton variant="tonal" trailingAccessibilityLabel="More send options">
Send
</SplitButton>

Sizes​

The five MD3 Expressive sizes set the height, the padding, the icon sizes and the inner corners.

SizeHeightTrailing iconInner corner
extraSmall32dp22dp4dp
small (default)40dp22dp4dp
medium56dp26dp4dp
large96dp38dp8dp
extraLarge136dp50dp12dp

At extraSmall and small, each button adds vertical touch area to reach 48dp. It adds none on the sides, because the two buttons are 2dp apart.

<SplitButton size="medium" trailingAccessibilityLabel="More send options">
Send
</SplitButton>

The expanded state​

The trailing button is a toggle. While expanded is true:

  • The trailing button becomes fully round.
  • The default chevron turns 180°.
  • The trailing button takes a state layer of the content color.

It works controlled (expanded and onExpandedChange) or uncontrolled (defaultExpanded).

Icons​

leadingIcon and trailingIcon accept the same forms as Button: a string name, a pre-rendered element, or a render function that receives { size, color }. See the Icons guide for the details.

trailingIcon defaults to chevron-down. An icon that you pass doesn't turn when the button expands.

The leading button can show only an icon. Omit the label and pass accessibilityLabel:

<SplitButton
leadingIcon="reply-outline"
accessibilityLabel="Reply"
trailingAccessibilityLabel="More reply options"
/>

Disabled​

disabled disables both buttons.

<SplitButton disabled trailingAccessibilityLabel="More save options">
Save
</SplitButton>

Overrides​

containerColor and contentColor apply to both buttons. The component derives the hover and press colors from them. labelStyle styles the label text, and style styles the row that holds the two buttons.

<SplitButton
containerColor="#E8DEF8"
contentColor="#4A148C"
trailingAccessibilityLabel="More theme options"
>
Theme
</SplitButton>

Motion​

  • The inner corners of a pressed button get rounder: 4dp to 12dp at the default size.
  • The trailing button morphs between its rest shape and the round shape.
  • The chevron turns with the same motion.

With reduced motion on, each change has no animation.

Accessibility​

  • Each button reports role="button". The leading button takes its name from the label or from accessibilityLabel.
  • The trailing button has no text, so trailingAccessibilityLabel is required. Say what the menu holds, for example "More save options".
  • The trailing button reports the expanded state through aria-expanded.
  • As the anchor of a Menu, the trailing button also reports aria-haspopup="menu". The row itself reports nothing, because it isn't a control.
  • Each button shows a keyboard focus ring (secondary, 3dp).
  • In a right-to-left layout, the trailing button is on the left, and the corners mirror.

Props​

PropTypeDefaultRequiredDescription
childrenstring-NoText label of the leading button. Omit it for an icon-only leading button, and then pass `accessibilityLabel`.
variantenumfilledNoVisual variant of both buttons.
sizeenumsmallNoMD3 Expressive size of both buttons: 32, 40, 56, 96 or 136 dp tall.
leadingIconIconSource-NoIcon of the leading button, before the label. Accepts a string name (resolved via the theme's `iconResolver`, for example `mdiResolver`), a pre-rendered element, or a render function that receives `{ size, color }`.
iconSizenumber-NoSize of the leading icon in dp. Defaults to the icon size of the `size` (20 for `extraSmall` and `small`, 24 for `medium`, 32 for `large`, 40 for `extraLarge`). The trailing icon keeps the size of its token.
trailingIconIconSource'chevron-down'NoIcon of the trailing button. Accepts the same forms as `leadingIcon`. The default chevron turns 180° while `expanded` is true. An icon that you pass doesn't turn.
onPressPressableProps-NoCalled when the leading button is pressed.
onLongPressPressableProps-NoCalled when the leading button is long-pressed.
expandedboolean-NoControls the trailing button: `true` while the menu that it opens is visible. The trailing button then becomes fully round. Pair it with `onExpandedChange`, or use `defaultExpanded` for an uncontrolled button.
defaultExpandedbooleanNoInitial state of an uncontrolled trailing button: it flips its own state on press and reports it through `onExpandedChange`.
onExpandedChange(expanded: boolean) => void-NoCalled with the next state when the trailing button is pressed.
accessibilityLabelstring-NoAccessibility label of the leading button. Defaults to the label text.
trailingAccessibilityLabelstring-YesAccessibility label of the trailing button, which has no text. Say what the menu holds, for example "More save options".
disabledbooleanNoDisables both buttons.
containerColorstring-NoOverride the container (background) color of both buttons. State-layer colors (hover, press) are derived automatically.
contentColorstring-NoOverride the content (label and icon) color of both buttons. State-layer colors are derived automatically when no containerColor is set.
labelStyleStyleProp<TextStyle>-NoAdditional style applied to the label text.
styleStyleProp<ViewStyle>-NoStyle applied to the row that holds the two buttons.