Skip to main content
SegmentControl ← Back to Table of Contents

Summary

iOS-style single-select segmented control.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\SegmentControl
State typestring|int — one option key
Model cast'alignment' => 'string'
FieldTypesegment_control

Basic usage

use Bjanczak\FilamentFlexFields\Filament\Forms\Components\SegmentControl;

SegmentControl::make('alignment')
    ->label('Alignment')
    ->options([
        'left' => 'Left',
        'center' => [
            'label' => 'Center',
            'icon' => 'heroicon-o-bars-3',
            'tooltip' => 'Centered text',
        ],
        'right' => 'Right',
    ])
    ->variant('ghost')
    ->fullWidth();

Validation

Built-in Rule::in(...) against option keys.

Configuration API

options(array|Closure $options)

KeyTypeDescription
labelstringSegment label
iconstring|nullHeroicon (or use icons())
tooltipstring|nullHover tooltip
disabledboolDisables this segment
Simple form: 'left' => 'Left'.
SegmentControl::make('field_name')
    ->options([
        'option_1' => 'Option 1',
        'option_2' => 'Option 2',
    ]);

icons(array|Closure $icons)

Map of option key → Heroicon name.
SegmentControl::make('field_name')
    ->icons([
        'option_1' => 'heroicon-o-star',
        'option_2' => 'heroicon-o-heart',
    ]);

disabledOptions(array|Closure $keys)

Disable segments by key.
SegmentControl::make('field_name')
    ->disabledOptions(['option_2']);

variant(string|Closure $variant)

ValueDescription
defaultFilled track background. Default.
ghostTransparent track; uses color() for selection accent.
SegmentControl::make('field_name')
    ->variant('primary');

color(string|Closure|null $color)

Selection accent color. For ghost, defaults to primary when omitted.
SegmentControl::make('field_name')
    ->color('primary');

separators(bool|Closure $condition = true)

Vertical dividers between segments. Default: true.
SegmentControl::make('field_name')
    ->separators(true);

fullWidth(bool|Closure $condition = true)

Stretch the control to the full field width.
SegmentControl::make('field_name')
    ->fullWidth(true);

iconOnly(bool|Closure $condition = true)

Hide labels; show icons only. Requires icons on options.
SegmentControl::make('field_name')
    ->iconOnly(true);

expandSelectedLabel(bool|Closure $condition = true)

Animates the selected segment to a wider width (label expansion).
SegmentControl::make('field_name')
    ->expandSelectedLabel(true);

size(string|ControlSize|Closure $size)

See Control size.
SegmentControl::make('field_name')
    ->size('md');

FlexField schema config

Config keyMaps to
optionsoptions()
sizesize()
variantvariant()
full_widthfullWidth()
iconsicons()
disabled_optionsdisabledOptions()
colorcolor()
separatorsseparators()
icon_onlyiconOnly()
expand_selected_labelexpandSelectedLabel()