V Vaylan UI
Data input

Toggle

Switch a boolean setting with visible context.

Preview

Change the example value; the preview reports the current state.

Example

<.toggle field={@form[:notifications]} label="Email notifications" color={:primary} />

API contract

toggle/1 uses declared Phoenix attributes and slots. This table is generated from the compiled component metadata.

AttributeTypeRequiredDefault Accepted values
field {:struct, Phoenix.HTML.FormField} No nil Any value matching the declared type
id :string No nil Any value matching the declared type
name :string No nil Any value matching the declared type
label :string Yes — Any value matching the declared type
value :any No "true" Any value matching the declared type
checked :boolean No false Any value matching the declared type
description :string No nil Any value matching the declared type
errors :list No [] Any value matching the declared type
color :atom No nil [nil, :neutral, :primary, :secondary, :accent, :info, :success, :warning, :error]
size :atom No nil [:xs, :sm, :md, :lg, :xl, nil]
hidden_input :boolean No true Any value matching the declared type
class :any No nil Any value matching the declared type
rest :global No — global includes ["disabled", "form", "required"]

States and behavior

Default, disabled, described, and server-invalid states are supported. Text-like fields also pass applicable native read-only and required attributes.

Keyboard and accessibility

Behavioral tests

These automated checks are applied to this component by the package and documentation test suites.

  • ExUnit

    Toggle field contract

    Preserves the native field name, checked and disabled states, visible label, description, and semantic color.

    test/vaylan_ui/components_test.exs
  • Docs

    Preview behavior contract

    Classified as input. Change the example value; the preview reports the current state.

    examples/docs/test/vaylan_ui_docs_web/controllers/page_controller_test.exs
  • Docs

    Stable public component page

    Renders the component name, example, API contract, accepted values, and keyboard and accessibility guidance at its stable URL.

    examples/docs/test/vaylan_ui_docs_web/controllers/page_controller_test.exs