Skip to content

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 Toggle for the pressed state of a button, such as toolbar formatting or view options. It is not a form field: use Checkbox for a boolean value saved with a form and Switch for a setting that takes effect immediately.
  • Compose it with Button or IconButton through render. Toggle carries only the focus ring and renders one <button> with aria-pressed.
  • Give an icon-only toggle one accessible name through aria-label on IconButton, and hide the glyph with aria-hidden. Keep the name the same in both states; aria-pressed reports the state.
  • Pair an icon-only toggle with a Tooltip that shows the same words as its name, with Toggle as the render of TooltipTrigger.
  • 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

KeyAction
EnterToggles the pressed state.
SpaceToggles 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.

Base UI Toggle docs

Data attributes
AttributeDescription
data-pressed

Present when the toggle button is pressed.

data-disabled

Present when the toggle button is disabled.