Skip to content
LIBRARYFormsUpdated

Segmented Control ​

MSegmentedControl selects one value from a compact set, such as a period, category or display mode. The app decides what changes when that value is selected.

Next alpha

Available in 0.1.0-alpha.4.

Web preview
Open example ↗

Usage ​

vue
<m-segmented-control
  v-model="period"
  label="Focus period"
  :options="[
    { value: 'day', label: 'Day' },
    { value: 'week', label: 'Week' },
    { value: 'month', label: 'Month' },
  ]"
/>

Declare period as ref<ChoiceValue | null>('week') in your component. Import the type from @getcortexlabs/mavis-core.

Props ​

PropTypeDefaultBehavior
optionsreadonly SegmentedOption[]requiredUnique value, nonempty label, optional disabled.
modelValueChoiceValue | nullnullSelected string or finite number.
labelstringrequiredNonempty accessible group name; no automatic visible label.
disabledbooleanfalseDisables the group.
wrapbooleanfalseAllows multiple rows when the options need more width.
width / grow / shrinkdimension / number / numberauto / 0 / contextLayout participation.
id / accessibilityHiddenstring / boolean— / falseIdentifier and accessibility exclusion.

update:modelValue requests an enabled value different from the current one. Selection stays controlled even if the app rejects the request. null, empty options or a missing value show no selection; the component does not choose a fallback or clear state automatically. Numeric and string values remain distinct. Duplicate values throw RangeError; invalid values and empty labels throw TypeError.

Layout and motion ​

Prefer two to four short labels. Segments share the available width equally, and text wraps without a fixed height. Large lists belong in Select or Radio. This control has no panels, scrolling, icons-only options, multiselection or router integration. Use Tabs for local content panels.

The marker stretches toward the selected segment and settles with the theme's bounce, with Jolt on both renderers and a light haptic on native. On Web the marker squashes slightly while pressed, and dragging across the control moves it between segments: releasing requests the segment under the pointer, and a refusal by the parent returns the marker to the current value. A short drag below six pixels stays a normal click. Native measurement changes snap to the new geometry; pending animation is stopped on background/unload. Both renderers respect reduced motion. Only the private marker is animated, preserving application transforms on the control.

Interaction ​

Web uses a radio group with one Tab stop. Arrow keys, Home and End focus and request selection while skipping disabled options. Horizontal keys follow text direction. Enter/Space activates a focused segment. Disabling a selected option keeps it selected until the app chooses another value.

Native options expose radio-button semantics, the group name as a hint and their checked/disabled states. Android supports Left/Right and Home/End; other native keyboard movement follows the platform. UIKit/Android font scaling can increase the control height. Platform typography and layout may differ in pixels.

On iOS with Core 9.1.3, disabled choices block taps but the native accessibility tree can omit the unavailable trait. Selection remains exposed; the trait follow-up is #112.

Help center uses the value to choose a question category, preserving expanded sections per category.

Full example ​

View source
vue
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, ref } from 'vue'
import type { ChoiceValue } from '@getcortexlabs/mavis-core'
import { useMavisTheme } from '@getcortexlabs/mavis-core/vue'

const { t, locale } = useCatalogLocale(() => props.lang)

const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })

const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const { theme } = useMavisTheme()
const range = ref<ChoiceValue | null>('week')
const disabled = ref(false)
const options = computed(() => [
  { value: 'day', label: pt.value ? 'Dia' : 'Day' },
  { value: 'week', label: pt.value ? 'Semana' : 'Week' },
  { value: 'month', label: pt.value ? 'Mês' : 'Month' },
])
const minutes = computed(() =>
  range.value === 'day' ? '45' : range.value === 'week' ? '280' : '1.240',
)
const bars = computed(() =>
  range.value === 'day'
    ? [30, 65, 45, 88, 60, 100, 75]
    : range.value === 'week'
      ? [40, 70, 95, 55, 90, 125, 105]
      : [75, 45, 105, 85, 115, 95, 135],
)
</script>
<template>
  <m-column id="segmented-demo" gap="lg">
    <m-column gap="sm">
      <m-text variant="overline" tone="accent">{{
        t(pt ? 'MUDE O PONTO DE VISTA' : 'CHANGE THE PERSPECTIVE')
      }}</m-text>
      <m-text variant="title">{{
        t(pt ? 'Seu ritmo, em perspectiva.' : 'Your rhythm, in perspective.')
      }}</m-text>
    </m-column>
    <m-segmented-control
      v-model="range"
      :options="options"
      :disabled="disabled"
      :label="t(pt ? 'Período de foco' : 'Focus period')"
    />
    <m-card gap="md" :backgroundColor="theme.colors.accentSoft">
      <m-row align="end" gap="sm"
        ><m-text variant="display" tone="accent">{{ t(minutes) }}</m-text
        ><m-text tone="accent">{{ t('min') }}</m-text></m-row
      >
      <m-text tone="muted">{{
        t(pt ? 'Tempo para as ideias que importam.' : 'Time for the ideas that matter.')
      }}</m-text>
      <m-row :height="140" align="end" gap="sm" :accessibilityHidden="true">
        <m-box
          v-for="(height, index) in bars"
          :key="index"
          :width="0"
          :grow="1"
          :height="height"
          radius="sm"
          :backgroundColor="index === 5 ? theme.colors.accent : theme.colors.surface"
        />
      </m-row>
      <m-text variant="caption" tone="muted">{{
        t(
          pt
            ? 'Valores ilustrativos, sem coleta de atividade.'
            : 'Illustrative values; no activity is collected.',
        )
      }}</m-text>
    </m-card>
    <m-switch v-model="disabled" :label="t(pt ? 'Bloquear seleção' : 'Disable selection')" />
    <m-column gap="sm">
      <m-text variant="caption" tone="muted">{{
        t(pt ? 'Uma opção pode ficar indisponível.' : 'An option can be unavailable.')
      }}</m-text>
      <m-segmented-control
        :modelValue="'personal'"
        :options="[
          { value: 'personal', label: pt ? 'Pessoal' : 'Personal' },
          { value: 'team', label: pt ? 'Equipe' : 'Team', disabled: true },
        ]"
        :label="t(pt ? 'Espaço de trabalho' : 'Workspace')"
      />
    </m-column>
  </m-column>
</template>

Set wrap when long labels need more room, including inside a sheet. The control measures the widest word and adds rows as its container narrows. Four options can form two rows of two. Each row fills the width, the marker follows the selected option across rows, and keyboard navigation keeps the original option order. The default is a single row.

Desktop ​

On the desktop the segments are buttons of equal width drawn with the colours of the theme; the control is one Tab stop and the arrow keys, Home and End ask for the next segment. The selection still belongs to your application; see Desktop components.

Components for NativeScript and Web. Starting with Vue.