Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Buttons

  • Button
  • ShimmerButton
  • InteractiveHoverButton
  • RainbowButton
  • PulsatingButton
  • RippleButton
  • ButtonGroup
  • SocialButton

Basic Inputs

  • Input
  • Textarea
  • CellEditor
  • Select
  • Checkbox
  • CheckboxGroup
  • Radio
  • Switch
  • Toggle
  • Segmented
  • Slider
  • NumberField
  • ElasticSlider

Advanced Inputs

  • MathTextarea
  • QuestionEditor
  • QuestionAnswer
  • MathField
  • SecretField
  • PasswordGenerator
  • Combobox
  • RemoteSelect
  • Listbox
  • Mentions
  • InputOTP
  • Rating
  • Upload
  • RegionSelect
  • ImageCropper
  • ScopeMatrix
  • Transfer
  • Cascader
  • TreeSelect
  • RegionCascader
  • CountrySelect
  • MarkdownEditor
  • Novel editor
  • RichTextEditor
  • CodeEditor
  • IssueReporter
  • ColorPicker
  • ColorField
  • ColorSwatchPicker
  • Choicebox
  • EmojiPicker
  • VoiceRecord
  • IconPicker
  • InspectorPanel

Date and Time

  • Calendar
  • DatePicker
  • DateTimePicker
  • DateRangePicker
  • TimePicker
  • TimeField

Form Frameworks

  • Form
  • ModalForm / DrawerForm
  • ProForm
  • StepsForm
  • LoginForm
  • AuthPanel
  • ClickCaptcha
  • Label
  • Field
  • SearchForm

Toggle

toggle

Switches a single action or formatting option between pressed and unpressed states.

Usage

Basic usage

A single Toggle is a switchable pressed button, and defaultPressed is initially selected.

tsx
<>
  <Toggle aria-label="bold"><Bold className="size-4" /></Toggle>
  <Toggle defaultPressed aria-label="bold"><Bold className="size-4" /></Toggle>
</>

Single choice group

ToggleGroup Default mutually exclusive radio selection, suitable for switching such as alignment.

tsx
<ToggleGroup defaultValue={["center"]}>
  <Toggle value="left" aria-label="Left justified"><AlignLeft className="size-4" /></Toggle>
  <Toggle value="center" aria-label="center"><AlignCenter className="size-4" /></Toggle>
  <Toggle value="right" aria-label="right-justified"><AlignRight className="size-4" /></Toggle>
</ToggleGroup>

Multiple choice group

Add multiple to allow multiple items in the group to be pressed at the same time, suitable for rich text styles.

tsx
<ToggleGroup multiple defaultValue={["bold", "italic"]}>
  <Toggle value="bold" aria-label="bold"><Bold className="size-4" /></Toggle>
  <Toggle value="italic" aria-label="italic"><Italic className="size-4" /></Toggle>
  <Toggle value="underline" aria-label="underline"><Underline className="size-4" /></Toggle>
</ToggleGroup>

Variants

default soft bottom / outline main color solid / pill rounded corners chip (AI toolbar switch style).

tsx
<>
  <Toggle defaultPressed aria-label="default"><Bold className="size-4" /></Toggle>
  <Toggle variant="outline" defaultPressed aria-label="outline"><Bold className="size-4" /></Toggle>
  <Toggle variant="pill" size="sm" defaultPressed aria-label="Deep Thought">
    <Sparkles className="size-3.5" /> Deep Thoughts
  </Toggle>
</>

Disabled

disabled Lock button, which can also be disabled when pressed.

tsx
<Toggle disabled defaultPressed aria-label="bold"><Bold className="size-4" /></Toggle>

When to use

Use Toggle for an icon or text button with a persistent pressed state, such as Bold, alignment, or an AI toolbar mode. ToggleGroup coordinates mutually exclusive or multiple pressed items. Use Switch for an immediately applied setting, or Radio for a conventional group of equivalent form choices.

Import

ts
import { Toggle, ToggleGroup, toggleVariants } from "@hulianui/ui"

Props

Toggle

NameTypeDefaultDescription
pressedboolean-controlled pressed state
defaultPressedbooleanfalseUncontrolled initial press state
disabledbooleanfalseDisable
valuestring-Identifies the item within the ToggleGroup
variant"default"|"outline"|"pill""default"default=grey background soft selection / outline=main color solid / pill=rounded stroke + soft main color selection (AI toolbar switch style)
size"sm"|"md""md"-
classNamestring--
aria-labelstring-Required if only icon

ToggleGroup

NameTypeDefaultDescription
valuestring[]-Controlled: item value array has been pressed
defaultValuestring[]-Uncontrolled initial item-by-item array
disabledbooleanfalseDisable entire group
multiplebooleanfalsetrue=multiple selections coexist; false=single selections are mutually exclusive
orientation"horizontal"|"vertical""horizontal"-
classNamestring--

Events

Toggle

EventTypeDescription
onPressedChange(pressed: boolean) => voidPressed state change (Hulian converges signature, loses Base UI eventDetails)

ToggleGroup

EventTypeDescription
onValueChange(value: string[]) => voidchange callback

Slots

Toggle

SlotTypeDescription
childrenReactNodeicon / text

ToggleGroup

SlotTypeDescription
childrenReactNodeItem Toggle is included

Example

Single toggle (controlled):

tsx
const [on, setOn] = useState(false);
<Toggle pressed={on} onPressedChange={setOn} aria-label="Bold">
  <Bold className="size-4" />
</Toggle>

Mutually exclusive radio group:

tsx
<ToggleGroup defaultValue={["center"]}>
  <Toggle value="left" aria-label="Align left"><AlignLeft className="size-4" /></Toggle>
  <Toggle value="center" aria-label="Align center"><AlignCenter className="size-4" /></Toggle>
  <Toggle value="right" aria-label="Align right"><AlignRight className="size-4" /></Toggle>
</ToggleGroup>

Usage guidelines

  • ToggleGroup always represents pressed items as a value array; with multiple={false}, the array contains zero or one value.
  • An icon-only Toggle needs aria-label so screen readers can identify the action.
  • Controlled usage requires pressed/onPressedChange, or group value/onValueChange. Use defaultPressed or defaultValue only when uncontrolled.

Related

Input · Textarea · Select · Checkbox · CheckboxGroup · Radio

Playground

<Toggle>
  <Bold />
</Toggle>
PreviousSwitchFormsNextSegmented

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Events
    • Slots
    • Example
    • Usage guidelines
    • Related
  • Playground