Field type
toggle / toggle-group
Two related controls. toggle is an on/off switch storing a boolean. toggle-group is a single-select segmented control storing the chosen value as a string.
Type: toggle, toggle-group (alias listed in the doc) · Stored attribute type: boolean
Stored value
boolean (toggle) or string (toggle-group)
Supports
- Simple on/off boolean via
toggle - Single-select segmented control via
toggle-group - Pairs naturally with
conditionalLogicto gate other fields
Config options
| Option | Type | Default | Description |
|---|---|---|---|
options | { value, label }[] | toggle-group only. The choices shown as segments. Required for toggle-group. | |
default | boolean or string | For toggle a boolean; for toggle-group the pre-selected value (should match one of the options or no segment will be active). |
Gotchas
- For multi-select use
checkbox-group(alias:button-group). The two are picked by the SHAPE of the saved value, not by visual style.
Example
// toggle
{ "id": "ctrl_pinned",
"type": "toggle",
"label": "Pin to top",
"attributeKey": "is_pinned",
"default": false,
"parentPanelId": "panel" }
// toggle-group
{ "id": "ctrl_source",
"type": "toggle-group",
"label": "Source",
"attributeKey": "source",
"default": "latest",
"options": [
{ "value": "latest", "label": "Latest" },
{ "value": "manual", "label": "Pick" }
],
"parentPanelId": "panel" }Consume
JSX
export default function Collection({ attributes }) {
const source = attributes.source === 'manual' ? 'manual' : 'latest';
// ... branch on `source`
}PHP
<?php
$source = ($attributes['source'] ?? 'latest') === 'manual' ? 'manual' : 'latest';
// ... branch on $sourceEvery field also takes the keys common to all fields.