Primitives
The toggle group primitive is a collection of toggle buttons that can be used to select one or more options.
Import the ToggleGroup primitives from ng-primitives/toggle-group
.
Assemble the toggle-group directives in your template.
Create a reusable component that uses the toggle group directives.
Generate a reusable toggle group component using the Angular CLI.
path
: The path at which to create the component file.prefix
: The prefix to apply to the generated component selector.componentSuffix
: The suffix to apply to the generated component class name.fileSuffix
: The suffix to apply to the generated component file name. Defaults to component
.exampleStyles
: Whether to include example styles in the generated component file. Defaults to true
.Here are some additional examples of how to use the Toggle Group primitives.
The toggle group can be configured to allow multiple selections by setting the ngpToggleGroupType
input to multiple
.
The following directives are available to import from the ng-primitives/toggle-group
package:
The orientation of the toggle group.
Whether toggle buttons can be deselected. If set to `false`, clicking a selected toggle button will not deselect it.
The type of the toggle group, whether only one item can be selected or multiple.
The selected value(s) of the toggle group.
Whether the toggle group is disabled.
Emits when the value of the toggle group changes.
[ngpToggleGroup]
ngpToggleGroup
The following data attributes are available to style the toggle group:
Attribute | Description | Value |
---|---|---|
data-disabled |
Applied when the toggle group is disabled. | - |
data-orientation |
The orientation of the toggle group. | horizontal | vertical |
data-type |
The type of the toggle group. | single | multiple |
The value of the item.
Whether the item is disabled.
[ngpToggleGroupItem]
ngpToggleGroupItem
The following data attributes are available to style the toggle group item:
Attribute | Description | Value |
---|---|---|
data-disabled |
Applied when the toggle group item is disabled. | - |
data-selected |
Applied when the toggle group item is selected. | - |
You can configure the default options for all toggle-groups in your application by using the provideToggleGroupConfig
function in a providers array.
The default orientation of the toggle group.
The default type of the toggle group.
Copyright © 2025 Angular Primitives