Skip to main content

Button

A button with a title and a press handler. It renders a <button type="button">, so the keyboard and a screen reader see a real button.

import { Button } from 'react-native'

export function SaveButton({ onSave }) {
return <Button title="Save" onPress={onSave} />
}

Button takes no style and no children, as in React Native. For a different look, use Pressable or TouchableOpacity with role="button".

How it looks​

React Native draws a different button on each platform. The web uses the look of Android:

  • A background of #2196F3, with a corner radius of 2.
  • The title in white, with a weight of 500, centered, with 8 px around it.
  • When disabled: a background of #dfdfdf and a title of #a1a1a1.

Two things differ from Android:

  • The title keeps its case. Android makes it uppercase.
  • The button has no shadow, because the web ignores elevation.

The button dims while you press it, as TouchableOpacity does.

Inside a View, the button takes the full width, as on native. To make it as wide as its title, put it in a View with alignItems: 'flex-start'.

Props​

PropOn the web
titleThe text of the button. It must be a string, or Button throws, as in React Native.
onPressAs on Pressable. Enter and Space press a focused button.
colorThe background color, as on Android. On iOS, it's the color of the title.
disabledSets aria-disabled, takes the button out of the tab order, stops the press, and changes the colors.
accessibilityState, aria-disabledA disabled value in one of them also disables the button. The disabled prop wins.
accessibilityLabel, aria-label, accessibilityHintAs on View.
aria-busy, aria-checked, aria-expanded, aria-selectedGo to the button.
accessibilityLanguageSets the lang attribute.
importantForAccessibilityno and no-hide-descendants set aria-hidden, which hides the button and its title from a screen reader.
testIDSets data-testid.
accessible, accessibilityActions, onAccessibilityActionNative only. Accepted and ignored.
touchSoundDisabled, hasTVPreferredFocus, nextFocusDown and othersNative only. Accepted and ignored.

Ref​

The ref is the <button> element. It has the measure methods of View.