Skip to main content

IconButton

An icon button helps people take a supplementary action with one tap. It follows the Material Design 3 Icon Button specification.

The icon and selectedIcon props accept three forms: a string name (resolved through the iconResolver of the theme, for example mdiResolver for MaterialDesignIcons), a pre-rendered React element from any icon library, or a render function that receives the resolved { size, color }. See the Icons guide for the details, including how to register a global iconResolver for Lucide, SF Symbols, or custom SVGs.

Usage​

import { IconButton } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<IconButton
icon="heart-outline"
accessibilityLabel="Favorite"
onPress={() => {}}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Variants​

VariantUse case
filledHigh emphasis, filled container
tonalMedium emphasis, tonal container
outlinedMedium emphasis, outlined border
standardLow emphasis, no container

Sizes​

Five MD3 Expressive sizes. small is the default.

sizeHeightIcon
extraSmall32dp20dp
small40dp24dp
medium56dp24dp
large96dp32dp
extraLarge136dp40dp
import { IconButton } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { View } from 'react-native'

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 12 }}>
<IconButton icon="star" size="extraSmall" accessibilityLabel="Star" onPress={() => {}} />
<IconButton icon="star" size="small" accessibilityLabel="Star" onPress={() => {}} />
<IconButton icon="star" size="medium" accessibilityLabel="Star" onPress={() => {}} />
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Width and shape​

width changes the horizontal padding at a fixed height: 'narrow', 'uniform' (default), or 'wide'. At size="small" that is 32 / 40 / 52dp wide.

shape controls the container at rest. 'round' (default) rests as a circle or a pill. 'square' rests at a corner of theme.shape that depends on the size, so roundness and your own corner tokens reach it. A toggle button inverts its shape when selected, so a round toggle becomes square to signal the change.

<IconButton icon="star" width="wide" accessibilityLabel="Star" />
<IconButton icon="star" shape="square" accessibilityLabel="Star" />

Bring your own icon library​

import { IconButton } from '@rootnative/components'
import { Heart } from 'lucide-react-native'

<IconButton
icon={({ size, color }) => <Heart size={size} color={color} />}
accessibilityLabel="Like"
/>

The render-function form receives the size and the color that the IconButton gives to its default icon (24dp at the default small size, plus the variant and state color). So the icon follows each size and variant change for you.

Toggle Mode​

Use selected and selectedIcon for a toggle. selected with onSelectedChange is the controlled form. defaultSelected is the uncontrolled form: the button flips its own state on press and reports the new state through onSelectedChange.

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

export default function App() {
const [liked, setLiked] = useState(false)
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<IconButton
icon="heart-outline"
selectedIcon="heart"
selected={liked}
onSelectedChange={setLiked}
accessibilityLabel={liked ? 'Unlike' : 'Like'}
/>
</View>
</ThemeProvider>
</SafeAreaProvider>
)
}

Props​

PropTypeDefaultRequiredDescription
iconIconSource-YesIcon to display. 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 }`.
selectedIconIconSource-NoIcon to display when `selected` is `true` (toggle mode).
iconColorstring-NoOverrides the automatic icon color derived from the variant and state. In the `leading` or `trailing` slot of an `AppBar`, the automatic color of a `'standard'` button is the icon color of that slot, and its hover and press layers derive from that color. A selected toggle keeps `primary`. In a `Toolbar`, a `'standard'` button takes the toolbar color, and a selected toggle takes the selected container and icon colors of the toolbar.
contentColorstring-NoOverride the content (icon) color. Takes precedence over `iconColor` when both are provided.
containerColorstring-NoOverride the container (background) color. State-layer colors (hover, press) are derived automatically.
styleStyleProp<ViewStyle>-NoStyle for the component. The keys that place or size it in its parent — `alignSelf`, `flex`, `flexGrow`, `flexShrink`, `flexBasis`, `width`, the margins, `position`, the insets and `zIndex` — go to the outer wrapper, so the focus ring and the shadow move with it. `minWidth` and `maxWidth` go with a `width`; alone, they style the container. The wrapper sets no `alignSelf`, so the parent's `alignItems` places the component. In a parent that stretches its children, the component keeps its own width at the start edge. Every other key styles the container. Static form only — the function form `(state) => style` is not supported because the component drives its container background through Reanimated. Use `containerColor` / `contentColor` for state-aware styling.
onPress() => void-NoCalled when the button is pressed.
disabledbooleanNoDisables the button.
variantenumfilledNoVisual style variant.
selectedboolean-NoEnables toggle mode and controls it. The button changes appearance based on the selected/unselected state. Pair with `onSelectedChange`, or use `defaultSelected` for an uncontrolled toggle.
defaultSelectedboolean-NoEnables toggle mode without controlling it: the button flips its own state on press and reports it through `onSelectedChange`.
onSelectedChange(selected: boolean) => void-NoCalled with the next state when a toggle button is pressed.
sizeenumsmallNoMD3 Expressive size — one of `'extraSmall' | 'small' | 'medium' | 'large' | 'extraLarge'`. Sets container height and icon size.
widthenumuniformNoWidth variant. `'uniform'` is a square container; `'narrow'`/`'wide'` adjust horizontal padding around the icon.
shapeenumroundNoContainer shape. `'round'` is a pill/circle; `'square'` rests at the theme corner of the size: `cornerMedium` at `extraSmall` and `small`, `cornerLarge` at `medium`, and `cornerExtraLarge` at `large` and `extraLarge`. Toggle buttons invert the shape when selected.
accessibilityLabelstring-YesRequired — icon-only buttons must have a label for screen readers.