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.
| Variant | Use case |
|---|---|
filled (default) | The most important action on the screen |
tonal | An important action that needs less emphasis |
elevated | An action on a surface that needs separation |
outlined | A 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.
| Size | Height | Trailing icon | Inner corner |
|---|---|---|---|
extraSmall | 32dp | 22dp | 4dp |
small (default) | 40dp | 22dp | 4dp |
medium | 56dp | 26dp | 4dp |
large | 96dp | 38dp | 8dp |
extraLarge | 136dp | 50dp | 12dp |
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 fromaccessibilityLabel. - The trailing button has no text, so
trailingAccessibilityLabelis 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 reportsaria-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
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
children | string | - | No | Text label of the leading button. Omit it for an icon-only leading button, and then pass `accessibilityLabel`. |
variant | enum | filled | No | Visual variant of both buttons. |
size | enum | small | No | MD3 Expressive size of both buttons: 32, 40, 56, 96 or 136 dp tall. |
leadingIcon | IconSource | - | No | Icon 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 }`. |
iconSize | number | - | No | Size 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. |
trailingIcon | IconSource | 'chevron-down' | No | Icon 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. |
onPress | PressableProps | - | No | Called when the leading button is pressed. |
onLongPress | PressableProps | - | No | Called when the leading button is long-pressed. |
expanded | boolean | - | No | Controls 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. |
defaultExpanded | boolean | | No | Initial state of an uncontrolled trailing button: it flips its own state on press and reports it through `onExpandedChange`. |
onExpandedChange | (expanded: boolean) => void | - | No | Called with the next state when the trailing button is pressed. |
accessibilityLabel | string | - | No | Accessibility label of the leading button. Defaults to the label text. |
trailingAccessibilityLabel | string | - | Yes | Accessibility label of the trailing button, which has no text. Say what the menu holds, for example "More save options". |
disabled | boolean | | No | Disables both buttons. |
containerColor | string | - | No | Override the container (background) color of both buttons. State-layer colors (hover, press) are derived automatically. |
contentColor | string | - | No | Override the content (label and icon) color of both buttons. State-layer colors are derived automatically when no containerColor is set. |
labelStyle | StyleProp<TextStyle> | - | No | Additional style applied to the label text. |
style | StyleProp<ViewStyle> | - | No | Style applied to the row that holds the two buttons. |