Button Group
A Button Group component groups multiple buttons together for selecting from a set of related actions or options.
React Native components render to native views, so this is the component running in the example app, in the theme you are reading in.
9:41


ButtonGroup.tsx
import { View } from 'react-native';import { useState } from 'react';import { NButtonGroup, NText } from '@nayan-ui/native';export default function ButtonGroupScreen() {const [align, setAlign] = useState('left');const [size, setSize] = useState('md');return (<View className="p-4 gap-4"><NText className="text-lg font-bold">Basic</NText><NButtonGroupitems={[{ label: 'Left', value: 'left' },{ label: 'Center', value: 'center' },{ label: 'Right', value: 'right' }]}value={align}onValueChange={setAlign}/><NText>Selected: {align}</NText><NText className="text-lg font-bold">Different items</NText><NButtonGroupitems={[{ label: 'S', value: 'sm' },{ label: 'M', value: 'md' },{ label: 'L', value: 'lg' },{ label: 'XL', value: 'xl' }]}value={size}onValueChange={setSize}/><NText className="text-lg font-bold">Disabled</NText><NButtonGroupisDisableditems={[{ label: 'A', value: 'a' },{ label: 'B', value: 'b' }]}value="a"onValueChange={() => {}}/></View>);}
| Name | Type | Default | Details |
|---|---|---|---|
| items | ButtonGroupItem[] | Required | Array of items with label, value, optional icon and isDisabled. |
| value | string | Required | Currently selected value. |
| onValueChange | (value: string) => void | Required | Callback when selection changes. |
| label | string | Optional | Label for the button group. |
| isDisabled | boolean | false | Whether the button group is disabled. |
| className | string | ' ' | You can customise by passing tailwind classes. |
| buttonClassName | string | ' ' | You can customise by passing tailwind classes. |
| labelClassName | string | ' ' | You can customise by passing tailwind classes. |
| selected | string | Optional | Alias of value. |
| onChange | (value: string) => void | Optional | Alias of onValueChange. |
| disabled | boolean | false | Alias of isDisabled. |
Other components solving nearby problems.
- React Native Button Group
- React Native Toggle Buttons
- React Native Segmented Control
- Mobile Button Group React Native
- React Native Button Group Component
- React Native Button Group Library
- React Native Toggle Group
- React Native Radio Button Group
- React Native Tab Buttons
- React Native Switch Buttons
- React Native Toolbar Buttons
- Mobile Button Group Component
- Cross Platform Button Group
- Expo Button Group Component
- React Native Button Group Tutorial
- React Native Button Group TypeScript
- React Native Button Group UI