Skip to main content

Switch

Switch is a form control that lets people turn a setting on or off, such as email updates or autosave.

Import

import { Switch } from '@vortexlabs/vortex-native';
import type { SwitchProps } from '@vortexlabs/vortex-native';

Other links

import { Switch } from "@vortexlabs/vortex-native";

<Switch
  layout="default"
  size="md"
  disabled={false}
  labelAfter={false}
>
  Email updates
</Switch>

Features

  • Supports tapping and dragging the thumb.
  • Accepts a controlled value or an initial checked state.
  • Supports a settings-row layout and helper text.

Sizes

In the default layout, choose sm or md. The default size is md.

<Stack gap={3}>
  <Switch size="sm" defaultChecked>Small</Switch>
  <Switch size="md" defaultChecked>Medium</Switch>
</Stack>

Label Position

The label appears before the switch by default. Set labelAfter to place the control first.

<Stack gap={3}>
  <Switch defaultChecked>Label before</Switch>
  <Switch labelAfter defaultChecked>Label after</Switch>
</Stack>

Settings Row

Use the list layout for a full-width settings row. Helper text explains what changes when the switch is on.

<Switch layout="list" defaultChecked helperText="Save edits as you type.">
  Autosave
</Switch>

Controlled State

Use checked and onChange when your app owns the setting. Use defaultChecked for an initial value.

import { Switch } from "@vortexlabs/vortex-native";
import { useState } from "react";

export const AutosaveSetting = () => {
  const [autosave, setAutosave] = useState(true);

  return (
    <Switch
      checked={autosave}
      onChange={({ checked }) => setAutosave(checked)}
      helperText={autosave ? "Edits are saved as you type." : "Save your edits manually."}
    >
      Autosave
    </Switch>
  );
};

Disabled

Set disabled to prevent changes while keeping the current state visible.

<Switch defaultChecked disabled helperText="Managed by your organization.">
  Require device unlock
</Switch>

Accessibility

Description
Provide a visible label describing the setting. The switch exposes its checked and disabled states to assistive technology.