Segmented Control
A row of buttons where exactly one is selected, built from arc-option children.
<arc-segmented-control>Overview
SegmentedControl draws its <arc-option> children as buttons in one rounded, bordered bar. The selected button gets the accent background and a glow. Use it for two to five short options where exactly one must be picked, like a daily, weekly or monthly view. For more options, use Select or RadioGroup.
The bar is a radiogroup and each button a radio with aria-checked. Arrow keys move the selection and wrap at the ends, Home and End jump to the first and last option, and focus follows the selection.
With no value set, the first option is selected, so the control always has a value. arc-change fires with the new value each time the selection changes.
Guidelines
Do
- Keep labels to one or two words so the bar doesn't overflow
Don't
- Don't use it to switch between views. Use Tabs
- Don't use it for a single on/off setting. Use Toggle
Features
- Each option's label is its text content, so markup inside an `<arc-option>` is dropped
- Disabled drops the whole control to 50% opacity and blocks pointer events
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-segmented-control value="monthly">
<arc-option value="daily">Daily</arc-option>
<arc-option value="weekly">Weekly</arc-option>
<arc-option value="monthly">Monthly</arc-option>
</arc-segmented-control>import { SegmentedControl, Option } from '@arclux/arc-ui-react';
export default function Example() {
return (
<SegmentedControl value="monthly">
<Option value="daily">Daily</Option>
<Option value="weekly">Weekly</Option>
<Option value="monthly">Monthly</Option>
</SegmentedControl>
);
}<script setup>
import { SegmentedControl, Option } from '@arclux/arc-ui-vue';
</script>
<template>
<SegmentedControl value="monthly">
<Option value="daily">Daily</Option>
<Option value="weekly">Weekly</Option>
<Option value="monthly">Monthly</Option>
</SegmentedControl>
</template><script>
import { SegmentedControl, Option } from '@arclux/arc-ui-svelte';
</script>
<SegmentedControl value="monthly">
<Option value="daily">Daily</Option>
<Option value="weekly">Weekly</Option>
<Option value="monthly">Monthly</Option>
</SegmentedControl>import { Component } from '@angular/core';
import { SegmentedControl, Option } from '@arclux/arc-ui-angular';
@Component({
imports: [SegmentedControl, Option],
template: `
<arc-segmented-control value="monthly">
<arc-option value="daily">Daily</arc-option>
<arc-option value="weekly">Weekly</arc-option>
<arc-option value="monthly">Monthly</arc-option>
</arc-segmented-control>
`,
})
export class MyComponent {}import { SegmentedControl, Option } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<SegmentedControl value="monthly">
<Option value="daily">Daily</Option>
<Option value="weekly">Weekly</Option>
<Option value="monthly">Monthly</Option>
</SegmentedControl>
);
}import { SegmentedControl, Option } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<SegmentedControl value="monthly">
<Option value="daily">Daily</Option>
<Option value="weekly">Weekly</Option>
<Option value="monthly">Monthly</Option>
</SegmentedControl>
);
}API
valuestring''- The value of the currently selected option. Reflected as an attribute and auto-set to the first selectable option if empty.
namestring''- The form field name submitted with the selected value. Required for native form integration: without it, the selection will not appear in FormData.
disabledbooleanfalse- Disables the entire control, reducing opacity to 40% and blocking pointer events.
formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalsereadonlybooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-changedetail:{ value: string }- Fired when the selected segment changes
Option
<arc-option>One option in the bar. `value` identifies it and its text content is the label.
label- Expose text content as label
valuestring''- The value identifier for this option, used to match against the parent control value.
disabledbooleanfalse- When true, dims this option and prevents it from being selected.
selectedbooleanfalse