Skip to main content
Neural UIv2.0.0Documentation
View v1 GitHub

ToggleButtonGroup

Select one or several options with a segmented button group.

Category
Actions
Import
@neural-ui/core/toggle-button-group
Selector
neu-toggle-button-group
import { NeuToggleButtonGroupComponent } from '@neural-ui/core/toggle-button-group';

Usage

Use mode="single" for a scalar or null; mode="multiple" uses a readonly array. deselectable allows an active option to be cleared. options supports disabled entries and optional application icons. The item Template replaces visual content while Core retains the pressed state and native button.

Examples

Try this application-owned interaction. Its event handling and initial data are included in Code.

Examples

Current value: [ "week" ]

Events: 0

Try and configure

Change the public options, try the result and inspect the updated template. Code contains the complete executable implementation.

Try and configure

Current value: "week"

Events: 0

template.html
<neu-toggle-button-group
  mode="single"
  [options]="options()"
  [value]="value()"
  (valueChange)="acceptValue($event)"
  [size]="'md'"
  [deselectable]="true"
  [disabled]="false"
  [readonly]="false"
  [invalid]="false"
></neu-toggle-button-group>

State and events

Use mode="single" for a scalar or null; mode="multiple" uses a readonly array. deselectable allows an active option to be cleared. options supports disabled entries and optional application icons. The item Template replaces visual content while Core retains the pressed state and native button.

Accessibility and keyboard

Arrow keys move focus between enabled options; Enter/Space select. Tab enters and leaves the group.

Key
Action
Tab Enter or leave the group.
Arrow keys Move focus between available options; horizontal movement follows text direction.
Home Focus the first available option.
End Focus the last available option.
Enter Select the focused option.
Space Select the focused option.

API

Inputs, models and Outputs are extracted from the installed Core package. Named public types link to their definitions. Templates below include executable examples.

Inputs

Configure the component with [property]="value". Your application supplies these values; the component does not replace the state you pass in.

Name
Type
Default
Template binding
Description
compareWith(left: NeuToggleValue<T, V>, right: NeuToggleValue<T, V>) => booleanObject.isDerived default[compareWith]Comparison function for selected values; use stable domain identity.
deselectablebooleantrue[deselectable]Allow an already selected option to be deselected.
dirtybooleanfalse[dirty]Form state indicating that the user has changed the value.
disabledbooleanfalse[disabled]Prevents interaction with this control.
errorsreadonly ValidationError.WithOptionalFieldTree[][][errors]Validation errors supplied by the form or the application.
hiddenbooleanfalse[hidden]Hides the control according to the form state.
invalidbooleanfalse[invalid]Displays the invalid state; it does not add a validation rule.
modeM'single' as MDerived default[mode]single accepts one value; multiple accepts a readonly array of values.
optionDisabledNeuOptionDisabledAccessor<NeuToggleOptionModel<T, V>> | nullnull[optionDisabled]Field name or function that marks an option as disabled.
optionLabelNeuOptionLabelAccessor<NeuToggleOptionModel<T, V>> | nullnull[optionLabel]Field name or function used to obtain the visible option label.
optionsreadonly NeuToggleOptionModel<T, V>[][][options]Loaded option records. Accessors allow using your own domain objects.
optionValue(option: NeuToggleOptionModel<T, V>) => NeuToggleValue<T, V>(option) => resolveNeuOptionValue<NeuToggleOptionModel<T, V>, NeuToggleValue<T, V>>(option)Derived default[optionValue]Field name or function used to obtain the stored option value.
pendingbooleanfalse[pending]Form state indicating that asynchronous validation is pending.
readonlybooleanfalse[readonly]Keeps the applied value visible but prevents user edits.
requiredbooleanfalse[required]Marks the field as required; use a form validator to enforce it.
sizeNeuButtonSize'md'[size]Control size. The accepted scale or numeric unit is specified by its type.
touchedbooleanfalse[touched]Form state indicating that the control has been visited.

Models

A model supports [(property)]="signal" or the [property] and (propertyChange) pair. Choose one form, not both.

Name
Type
Default
Template binding
Description
valueNeuSelectionValue<NeuToggleValue<T, V>, M>null as NeuSelectionValue<NeuToggleValue<T, V>, M>Derived default[(value)]Application-owned editable model value.

Outputs

Listen to an event with (event)="handler($event)". The table explains the data your handler receives and how to use it.

Name
Payload
Template binding
Description
optionActivatedNeuOptionActivatedEvent<NeuToggleOptionModel<T, V>, NeuToggleValue<T, V>>(optionActivated)="onOptionActivated($event)"Activated option, its value and the originating event.
touchvoid(touch)="onTouch($event)"Notifies the form that the control has been touched; not a value change.

Templates

ng-content projects content into the component. TemplateRef inputs receive a template; ng-template directives identify templates with a typed context. A directive shared by an entrypoint is not necessarily a slot of this component.

Name
Mechanism
Contract
NeuToggleButtonItemDirectiveView example Public template directive (entrypoint)ng-template[neuToggleButtonItem]

Each example demonstrates a different template. Switch between Demo and Code to inspect its implementation, imports and state.

NeuToggleButtonItemDirective

NeuToggleButtonItemDirective

NeuToggleButtonItemDirective

Current value: "week"

Events: 0

Public Types

Open a type to inspect its definition and interface fields.

Styles and tokens

Use the supported public tokens listed below. Surrounding layout belongs to your application; validate the result in light and dark modes and narrow containers.

Specific tokens

This component uses shared theme tokens rather than dedicated component hooks.

Shared tokens used

Override these on a local wrapper to affect this example. An override on :root affects other components that use the same token.

Token
Purpose here
Other impact
Default / fallback
--neu-border Normal control and cell borders Shared by other Core consumers; scope the override. rgba(15, 23, 42, 0.08)
--neu-primary Brand color for active controls and emphasis Shared by other Core consumers; scope the override. #007aff
--neu-primary-dark Dark brand shade; outline and ghost Button text in the light theme Shared by other Core consumers; scope the override. #005fcc
--neu-primary-fg Foreground drawn over the primary background Shared by other Core consumers; scope the override. #ffffff
--neu-primary-solid Solid brand action background Shared by other Core consumers; scope the override. #006ee6
--neu-primary-solid-fg Foreground of solid brand actions Shared by other Core consumers; scope the override. #ffffff
--neu-primary-solid-hover Hover background of solid brand actions Shared by other Core consumers; scope the override. #005fcc
--neu-radius Control corner radius Shared by other Core consumers; scope the override. 8px