Skip to main content
SegmentControl ← Back to Table of Contents

Summary

Single-select segmented control — alternative to radio lists or selects, with sliding animations, ghost variants, and optional icon-only modes.
ClassBjanczak\FilamentFlexFields\Filament\Forms\Components\SegmentControl
State typestring|int — one option key
Model cast'status' => 'string' · 'type' => 'integer'
FieldTypesegment_control
Playgroundsegment-control slug in Flex Fields playground

Basic usage

Standard segments

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

SegmentControl::make('status')
    ->options([
        'draft' => 'Draft',
        'review' => 'In Review',
        'published' => 'Published',
    ]);

Ghost variant with icons and full width

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

State & validation

Stored value

State is the option key from options().
$record->status; // string|null — e.g. 'published'

Validation rules (built-in)

RuleWhen
nullableAlways (unless required())
Rule::in(...)Value must match a configured option key
requiredWhen ->required()

Configuration API

All methods accept Closure unless noted.
MethodTypeDefaultDescription
options(array|Closure $options)Setup[]Option keys => labels or rich arrays (label, icon, disabled, tooltip).
icons(array|Closure $icons)Setup[]Map of option key => Heroicon name.
disabledOptions(array|Closure $keys)Setup[]Keys that cannot be selected.
variant(string|Closure $variant)Setup'default'Visual variant: default (filled track), ghost (transparent track).
color(string|Closure|null $color)SetupnullSelection accent color. Defaults to primary for ghost.
separators(bool|Closure $condition = true)SetuptrueVertical dividers between segments.
fullWidth(bool|Closure $condition = true)SetupfalseStretch the control to full field width.
iconOnly(bool|Closure $condition = true)SetupfalseHide labels; show icons only.
expandSelectedLabel(bool|Closure $condition = true)SetupfalseAnimate the selected segment to a wider width.
size(string|ControlSize|Closure $size)Setup'md'Control size: sm, md, lg.

Public helper methods

MethodReturnsDescription
getOptionKeys()array<int, string|int>Valid keys for validation.
getNormalizedOptions()arrayResolved options with metadata.
getVariant()stringCurrent variant.
getColor()?stringResolved accent color.

Real-world examples

Responsive device selector (Icon only)

SegmentControl::make('preview_device')
    ->iconOnly()
    ->options([
        'desktop' => ['icon' => 'heroicon-o-computer-desktop', 'label' => 'Desktop'],
        'tablet' => ['icon' => 'heroicon-o-device-tablet', 'label' => 'Tablet'],
        'phone' => ['icon' => 'heroicon-o-device-phone-mobile', 'label' => 'Phone'],
    ])
    ->default('desktop');

Date range selector (Ghost variant)

SegmentControl::make('date_range')
    ->variant('ghost')
    ->separators(false)
    ->options([
        '1w' => '1W',
        '4w' => '4W',
        '1y' => '1Y',
        'all' => 'ALL',
    ])
    ->default('4w');

Playground

/admin/flex-fields-playground/segment-control See Playground for setup.
ComponentWhen to use instead
SegmentTabsWhen segments should switch between different form schemas.
NpsFieldSurvey-specific scales (0–10) with survey semantics.
ChoiceCardsLarger, card-style selection surfaces.

CSS classes (reference)

ClassRole
fff-segment-controlRoot wrapper
fff-segment-control--variant-{default|ghost}Visual variant
fff-segment-control--{sm|md|lg}Size variant
fff-segment-control--full-widthFull width modifier
fff-segment-trackOptions container
fff-segment-indicatorAnimated selection background
fff-segment-itemIndividual segment wrapper
fff-segment-item--selectedActive segment state
fff-segment-item--disabledDisabled segment state