Toggle
A button with a pressed state, composed with Button or IconButton.
Retry the HTTP node up to three times before the workflow fails.
hero.tsx
Usage guidelines
- Use
Togglefor the pressed state of a button, such as toolbar formatting or view options. It is not a form field: useCheckboxfor a boolean value saved with a form andSwitchfor a setting that takes effect immediately. - Compose it with
ButtonorIconButtonthroughrender.Togglecarries only the focus ring and renders one<button>witharia-pressed. - Give an icon-only toggle one accessible name through
aria-labelonIconButton, and hide the glyph witharia-hidden. Keep the name the same in both states;aria-pressedreports the state. - Pair an icon-only toggle with a
Tooltipthat shows the same words as its name, withToggleas therenderofTooltipTrigger. - Style the pressed look at the call site with
data-pressed:and Dify state tokens. Switching to a filled glyph for the pressed state adds a cue that does not rely on color.
Anatomy
tsx
tsx
Examples
Text toggle
Render through Button when the toggle has a visible label.
text.tsx
Controlled pressed state
Control pressed with onPressedChange when the owner coordinates several toggles. Here pressing one rating clears the other, and the pressed rating switches to a filled icon.
Your workspace keeps workflow run logs for 30 days. Export them from the Logs page to keep them longer.
feedback.tsx
Keyboard
| Key | Action |
|---|---|
| Enter | Toggles the pressed state. |
| Space | Toggles the pressed state. |
API reference
Toggle
A two-state toggle button that exposes data-pressed for styling. Renders a <button> element.
Carries only focus-ring styles; compose with Button or IconButton via render.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ToggleState) => string | undefined) | No default | |
pressed | boolean | No default | |
defaultPressed | boolean | false | |
disabled | boolean | false | |
onPressedChange | ((pressed: boolean, eventDetails: BaseToggle.ChangeEventDetails) => void) | No default | |
value | Value | No default | |
render | ComponentRenderFn<HTMLProps, ToggleState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ToggleState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | true | |
| Attribute | Description |
|---|---|
data-pressed | Present when the toggle button is pressed. |
data-disabled | Present when the toggle button is disabled. |