Segmented Control

Compact single or multiple selection from a short visible set. Single mode is a named radio group; multiple mode is a named group of independently pressed buttons. Use a select or listbox for longer collections.

Usage

<script type="module" src="/assets/components/segmented-control/qds-segmented-control.js"></script>
<qds-segmented-control id="stage" label="Pipeline stage" value="all"></qds-segmented-control>
<script>
  document.querySelector('#stage').options = [
    { value: 'all', label: 'All stages' },
    { value: 'screening', label: 'Screening' },
    { value: 'diligence', label: 'Diligence' }
  ];
</script>

When assigning properties before the module loads, custom-element upgrade preserves them. Await customElements.whenDefined('qds-segmented-control') when calling methods or reading its current state.

API

Property / attribute Type Default Meaning
options property readonly option array [] Nonempty string value, label, optional disabled/group/description. Segments display the label; group/description metadata is retained for compatible choice models.
value property string empty Current first effective selection; assignment selects one value silently.
values property string[] [] Current available, enabled selections in option order. Multiple mode exposes the full set.
value attribute string absent Default/reset selection, distinct from the current property.
defaultValues property string[] attribute default Explicit reset values, including multiple defaults; takes precedence over the attribute.
multiple boolean false Independent pressed buttons; otherwise single radio selection.
label, aria-label, aria-labelledby string empty Visible label; optional explicit name or external label IDs. External label text is copied across the shadow boundary.
name, form string empty Native field name and optional associated form ID.
hint, error-text string empty Helper and constraint/author-error messages.
required boolean false At least one available, enabled selection. Make the requirement visible in the label or hint.
disabled boolean false Blocks all choices and omits submission; native disabled fieldsets are supported.
readonly boolean false Keeps selection while retaining keyboard focus/navigation. Explain a locked multiple choice in nearby text.
invalid boolean false Author-supplied invalid state.
validate-on / validateOn blur / input / submit blur Error display timing. Native invalid submission and reportValidity reveal errors.
size sm / md / lg md Visual sizing; targets remain at least 44px.

Invalid option records and duplicate values are omitted; first value occurrence wins. Empty labels fall back to the value. Input/output records and selection arrays are copied. Labels are text, never parsed as HTML. Requested identities may precede their option data: unavailable/disabled values do not appear in the effective selection or submission and resolve when their enabled option arrives. Replacing options retains a focused identity or focuses the first remaining enabled choice; an empty collection keeps focus on the named group.

Changing to single mode keeps the first effective selection in option order. When both current properties are supplied before upgrade, values is applied last. Programmatic values, defaults and option changes emit no input/change events.

Keyboard and accessibility

Events and forms

User changes emit input then change with { component, value, values, multiple }, bubbling across shadow roots. Clicking an already selected radio emits no change. Validation transitions emit qds-validity-change with validity/message information.

Native submission contributes one scalar or repeated entries under name in multiple mode. Unselected, unnamed and disabled controls contribute no entry. Reset restores defaults and hides interaction errors; browser state restoration restores current selections silently. Public APIs: validity, validationMessage, willValidate, checkValidity(), reportValidity(), setCustomValidity(message), focus(). Readonly/disabled choices are barred from constraint validation. Hints/errors retain their layout space when feedback changes.

Parts: label, options, option, hint, error. The shared choice base handles form state and validation; the standalone module imports no popup select or framework.

Quangular business use

Northwind’s /#/investments/pipeline, reachable through Investments > Pipeline, uses the generated QdsSegmentedControlComponent for a single stage and multiple sectors. A string and string-array FormControl narrow the visible opportunities. No selected sectors means all sectors; Reset filters restores that state and All stages. This is fictional fixture data with component-local filter state.

<q-qds-segmented-control formControlName="stage" label="Stage"
  [options]="stageOptions"></q-qds-segmented-control>
<q-qds-segmented-control formControlName="sectors" multiple label="Sectors"
  [options]="sectorOptions"></q-qds-segmented-control>

The generated adapter uses string values in single mode and string arrays in multiple mode, with disabled, reset, touched and native validation integration.

Native validation focus

checkValidity() checks constraints without moving focus. Native invalid submission, form.reportValidity() and the component’s reportValidity() reveal the error and focus the selected or first available segment. Repeated validation preserves visible option labels, selection and normal Tab order. Canceling the native invalid event suppresses the browser’s default validation focus; the validity result remains false. Reset restores the documented defaults.