- Getting Started
- Architecture
- The Basics
- Digging Deeper
-
EDGE Components
- Introduction
- Activity Indicator
- Badge
- Bottom Navigation
- Bottom Sheet
- Button
- Button Group
- Canvas
- Carousel
- Checkbox
- Chip
- Column
- Divider
- Gesture Area
- Icon
- Image
- Lazy Grid
- Layout & Styling
- List
- Menus
- Modal
- Pressable
- Progress Bar
- Radio Group
- Refreshable
- Row
- Scroll View
- Select
- Shapes
- Side Navigation
- Slider
- Spacer
- Stack
- Tab Row
- Text
- Text Input
- Toggle
- Top Bar
- Virtual List
- Web View
- Plugins
- Testing
- Publishing Your App
Button Group
Get the Jump app
You'll need the free Jump app to preview this page on your device. Install it, then scan the code again.
Overview#
A segmented single-choice selector. Each option is a pressable pill in a horizontal bar; the active one fills with
theme.primary. The group owns the selected-index state.
Use this for short, mutually-exclusive choices that fit on one row. For more options or longer labels use a
<native:tab-row> or <native:select>.
@php $period = 0; @endphp <native:button-group :options="['Daily', 'Weekly', 'Monthly']" native:model="period" /> <native:text class="text-sm text-theme-on-surface-variant">Showing {{ ['Daily', 'Weekly', 'Monthly'][$period] }} stats</native:text>
period is a public int property on your component — the @php line stands in for public int $period = 0;. Tapping a segment syncs the new index back automatically, so anything echoing $period re-renders.
Props#
options- Array of option labels (required, array of strings)value/selected-index- Currently selected index (optional, int, default:0)disabled- Disable the group (optional, boolean, default:false)sync-mode- How selection changes sync back to your component:live | blur | debounce(optional, usually set bynative:modelmodifiers)a11y-label- Accessibility label (optional)a11y-hint- Accessibility hint (optional)
Events#
@change- Component method called when the selection changes. Receives the new index as a parameter
Two-way Binding#
native:model binds the selected index to an integer property on your component — declare it as
public int $planTier = 1; and the group keeps it in sync:
@php $planTier = 1; @endphp <native:button-group :options="$tiers" native:model="planTier" /> <native:text class="text-sm text-theme-on-surface-variant">Selected plan: {{ $tiers[$planTier] }}</native:text>
Examples#
Period picker#
reportRange is a public int property on your component (public int $reportRange = 2;):
@php $reportRange = 2; @endphp <native:button-group :options="['Day', 'Week', 'Month', 'Year']" native:model="reportRange"/> <native:text class="text-sm text-theme-on-surface-variant">Report range: {{ ['Day', 'Week', 'Month', 'Year'][$reportRange] }}</native:text>
With manual change handler#
Instead of native:model, pass the current index with :value and handle changes yourself.
$difficulty is a public int property on your component, and setDifficulty(int $index) is the
method that receives the new index — assign it to $difficulty there:
@php $difficulty = 1; @endphp <native:button-group :options="['Easy', 'Medium', 'Hard']" :value="$difficulty" @change="setDifficulty"/> <native:text class="text-sm text-theme-on-surface-variant">Difficulty: {{ ['Easy', 'Medium', 'Hard'][$difficulty] }}</native:text>
Element#
use Nativephp\NativeUi\Elements\ButtonGroup; ButtonGroup::make() ->options(['Daily', 'Weekly', 'Monthly']) ->selectedIndex(1) ->onChange('setPeriod');
make()- Create a button groupoptions(array $options)- Option labelsselectedIndex(int $index)- Currently selected indexdisabled(bool $value = true)- Disable the groupa11yLabel(string $value)- Accessibility labela11yHint(string $value)- Accessibility hintsyncMode(string $mode)-live | blur | debounce(set bynative:modelmodifiers)onChange(string $method)- Component method invoked on change
in no time