# Switch

- Page: https://jiguang132.com/resources/material-ui/docs/switches
- Resource: Material UI (https://jiguang132.com/resources/material-ui.md)
- All guides: https://jiguang132.com/resources/material-ui/docs.md

Toggle an independent binary setting with a native Switch.

This guide covers Material UI Core with the default Emotion engine; extensions and additional demos are explicitly classified.

## Use case and business boundary

Changing checked does not save preferences; expose a label and handle any asynchronous failure in the host.

## Native composition and scope

`Switch`, `FormControl`, `FormGroup`, `FormLabel`, `FormControlLabel`

Preserve native Material UI composition and types; do not substitute JGuang UI/Base UI/Radix APIs. Example entries are not extra components.

## Native installation and initialization

```bash
npm install @mui/material@9.4.0 @emotion/react@11.14.0 @emotion/styled@11.14.1
```

Use native npm and Emotion, not an invented JGuang UI Registry URL. Place examples inside native ThemeProvider; choose CssBaseline or ScopedCssBaseline for the project. Inspect React, existing providers, lockfile and SSR first. Never overwrite files or conceal peer conflicts. This batch verified React 19.2.8; React 18 and below require matching react-is. See the included bilingual setup guide.

## Practical native parameters

These selected parameters are not a flattened universal API. Preserve the native declaring owner, slot structure, nullable values and generics.

| Owner.prop | Practical role | Declaration source |
| --- | --- | --- |
| `Switch.checked` | Controlled binary selection; pair with the native change callback. | `Switch` |
| `Switch.onChange` | Owning control's native callback; preserve its exact event/value/nullable signature. | `Switch` |
| `Switch.disabled` | Native disabled interaction state; not an authorization check. | `Switch` |
| `Switch.required` | Native required form constraint; the host still owns business validation. | `Switch` |

## Runnable native examples

Machine keys select example entries, not universal variant props. Native demo JSX/data stay unchanged; JGuang-authored acceptance fixtures are explicitly labelled.

- Basic switches · `BasicSwitches` · upstream native demo
- Label · `SwitchLabels` · upstream native demo
- Size · `SwitchesSize` · upstream native demo
- Color · `ColorSwitches` · upstream native demo
- Controlled · `ControlledSwitches` · upstream native demo
- Switches with FormGroup · `SwitchesGroup` · upstream native demo
- Customization · `CustomizedSwitches` · upstream native demo
- Label placement · `FormControlLabelPosition` · upstream native demo

## Actual usage example

Unmodified pinned native demo; copy its required local helper files together.

```tsx
import Switch from '@mui/material/Switch';

const label = { slotProps: { input: { 'aria-label': 'Switch demo' } } };

export default function BasicSwitches() {
  return (
    <div>
      <Switch {...label} defaultChecked />
      <Switch {...label} />
      <Switch {...label} disabled defaultChecked />
      <Switch {...label} disabled />
    </div>
  );
}

```

## Example dependency boundaries

`@mui/material/Switch`, `@mui/material/FormGroup`, `@mui/material/FormControlLabel`, `@mui/material/styles`, `@mui/material/colors`, `react`, `@mui/material/FormLabel`, `@mui/material/FormControl`, `@mui/material/FormHelperText`, `@mui/material/Stack`, `@mui/material/Typography`

Direct Icons/System/Utils example imports require their matching 9.4.0 packages. Relative data/helpers are part of the example closure, not extra components. Remote images and simulated operations do not supply a backend.

## Pinned upstream API metadata reference

These tables retain the upstream metadata, not a newly inferred generic type system. Conditional generics, inherited props and callback details are defined by the source declarations below. Theme defaults may override metadata defaults.

### Switch

```tsx
import Switch from '@mui/material/Switch';
import { Switch } from '@mui/material';
```

Native inheritance: `IconButton`. Parent/DOM props are not fabricated as additional own props.

| Prop | Required | Upstream metadata type / constraint | Metadata default |
| --- | --- | --- | --- |
| `checked` | no | `bool` | — |
| `checkedIcon` | no | `node` | — |
| `classes` | no | `object` | — |
| `color` | no | `'default' \| 'primary' \| 'secondary' \| 'error' \| 'info' \| 'success' \| 'warning' \| string` | `'primary'` |
| `defaultChecked` | no | `bool` | — |
| `disabled` | no | `bool` | — |
| `disableRipple` | no | `bool` | `false` |
| `edge` | no | `'end' \| 'start' \| false` | `false` |
| `icon` | no | `node` | — |
| `id` | no | `string` | — |
| `onChange` | no | `func` | — |
| `required` | no | `bool` | `false` |
| `size` | no | `'medium' \| 'small' \| string` | `'medium'` |
| `slotProps` | no | `{ input?: func \| object, root?: func \| object, switchBase?: func \| object, thumb?: func \| object, track?: func \| object }` | `{}` |
| `slots` | no | `{ input?: elementType, root?: elementType, switchBase?: elementType, thumb?: elementType, track?: elementType }` | `{}` |
| `sx` | no | `Array<func \| object \| bool> \| func \| object` | — |
| `value` | no | `any` | — |



### FormControl

```tsx
import FormControl from '@mui/material/FormControl';
import { FormControl } from '@mui/material';
```

| Prop | Required | Upstream metadata type / constraint | Metadata default |
| --- | --- | --- | --- |
| `children` | no | `node` | — |
| `classes` | no | `object` | — |
| `color` | no | `'primary' \| 'secondary' \| 'error' \| 'info' \| 'success' \| 'warning' \| string` | `'primary'` |
| `component` | no | `elementType` | — |
| `disabled` | no | `bool` | `false` |
| `error` | no | `bool` | `false` |
| `focused` | no | `bool` | — |
| `fullWidth` | no | `bool` | `false` |
| `hiddenLabel` | no | `bool` | `false` |
| `margin` | no | `'dense' \| 'none' \| 'normal'` | `'none'` |
| `required` | no | `bool` | `false` |
| `size` | no | `'medium' \| 'small' \| string` | `'medium'` |
| `sx` | no | `Array<func \| object \| bool> \| func \| object` | — |
| `variant` | no | `'filled' \| 'outlined' \| 'standard'` | `'outlined'` |



### FormGroup

```tsx
import FormGroup from '@mui/material/FormGroup';
import { FormGroup } from '@mui/material';
```

| Prop | Required | Upstream metadata type / constraint | Metadata default |
| --- | --- | --- | --- |
| `children` | no | `node` | — |
| `classes` | no | `object` | — |
| `row` | no | `bool` | `false` |
| `sx` | no | `Array<func \| object \| bool> \| func \| object` | — |



### FormLabel

```tsx
import FormLabel from '@mui/material/FormLabel';
import { FormLabel } from '@mui/material';
```

| Prop | Required | Upstream metadata type / constraint | Metadata default |
| --- | --- | --- | --- |
| `children` | no | `node` | — |
| `classes` | no | `object` | — |
| `color` | no | `'error' \| 'info' \| 'primary' \| 'secondary' \| 'success' \| 'warning' \| string` | — |
| `component` | no | `elementType` | — |
| `disabled` | no | `bool` | — |
| `error` | no | `bool` | — |
| `filled` | no | `bool` | — |
| `focused` | no | `bool` | — |
| `required` | no | `bool` | — |
| `sx` | no | `Array<func \| object \| bool> \| func \| object` | — |



### FormControlLabel

```tsx
import FormControlLabel from '@mui/material/FormControlLabel';
import { FormControlLabel } from '@mui/material';
```

| Prop | Required | Upstream metadata type / constraint | Metadata default |
| --- | --- | --- | --- |
| `control` | yes | `element` | — |
| `checked` | no | `bool` | — |
| `classes` | no | `object` | — |
| `disabled` | no | `bool` | — |
| `disableTypography` | no | `bool` | — |
| `inputRef` | no | `ref` | — |
| `label` | no | `node` | — |
| `labelPlacement` | no | `'bottom' \| 'end' \| 'start' \| 'top'` | `'end'` |
| `onChange` | no | `func` | — |
| `required` | no | `bool` | — |
| `slotProps` | no | `{ typography?: func \| object }` | `{}` |
| `slots` | no | `{ typography?: elementType }` | `{}` |
| `sx` | no | `Array<func \| object \| bool> \| func \| object` | — |
| `value` | no | `any` | — |


## Native source declarations

Declarations/imports are extracted from pinned source without flattening unions or external inheritance. Original English comments/types are source reference, not a claim of translated upstream prose. Shared types stay in their native packages.

### vendor/src/Switch/Switch.d.ts

```ts
import * as React from 'react';

import { SxProps } from '@mui/system';

import { OverridableStringUnion } from '@mui/types';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

import { SwitchBaseProps } from '../internal/SwitchBase';

import { SwitchClasses } from './switchClasses';

export interface SwitchPropsSizeOverrides {}

export interface SwitchPropsColorOverrides {}

export interface SwitchRootSlotPropsOverrides {}

export interface SwitchTrackSlotPropsOverrides {}

export interface SwitchThumbSlotPropsOverrides {}

export interface SwitchSwitchBaseSlotPropsOverrides {}

export interface SwitchInputSlotPropsOverrides {}

export interface SwitchSlots {
  /**
   * The component that renders the root slot.
   * @default 'span'
   */
  root: React.ElementType;
  /**
   * The component that renders the track slot.
   * @default 'span'
   */
  track: React.ElementType;
  /**
   * The component that renders the thumb slot.
   * @default 'span'
   */
  thumb: React.ElementType;
  /**
   * The component that renders the switchBase slot.
   * @default SwitchBase
   */
  switchBase: React.ElementType;
  /**
   * The component that renders the switchBase's input slot.
   * @default SwitchBaseInput
   */
  input: React.ElementType;
}

export type SwitchSlotsAndSlotProps = CreateSlotsAndSlotProps<
  SwitchSlots,
  {
    /**
     * Props forwarded to the root slot.
     * By default, the available props are based on the span element.
     */
    root: SlotProps<'span', SwitchRootSlotPropsOverrides, SwitchOwnerState>;
    /**
     * Props forwarded to the track slot.
     * By default, the available props are based on the span element.
     */
    track: SlotProps<'span', SwitchTrackSlotPropsOverrides, SwitchOwnerState>;
    /**
     * Props forwarded to the thumb slot.
     * By default, the available props are based on the span element.
     */
    thumb: SlotProps<'span', SwitchThumbSlotPropsOverrides, SwitchOwnerState>;
    /**
     * Props forwarded to the switchBase slot.
     * By default, the available props are based on the internal SwitchBase component.
     */
    switchBase: SlotProps<
      React.ElementType<SwitchBaseProps>,
      SwitchSwitchBaseSlotPropsOverrides,
      SwitchOwnerState
    >;
    /**
     * Props forwarded to the input slot.
     * By default, the available props are based on the input element.
     */
    input: SlotProps<'input', SwitchInputSlotPropsOverrides, SwitchOwnerState>;
  }
>;

export interface SwitchOwnerState extends Omit<SwitchProps, 'slots' | 'slotProps'> {}

export interface SwitchProps
  extends
    StandardProps<SwitchBaseProps, 'checkedIcon' | 'color' | 'icon' | 'slots' | 'slotProps'>,
    SwitchSlotsAndSlotProps {
  /**
   * The icon to display when the component is checked.
   */
  checkedIcon?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<SwitchClasses> | undefined;
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   * @default 'primary'
   */
  color?:
    | OverridableStringUnion<
        'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | 'default',
        SwitchPropsColorOverrides
      >
    | undefined;
  /**
   * If `true`, the component is disabled.
   */
  disabled?: boolean | undefined;
  /**
   * The icon to display when the component is unchecked.
   */
  icon?: React.ReactNode;
  /**
   * The size of the component.
   * `small` is equivalent to the dense switch styling.
   * @default 'medium'
   */
  size?: OverridableStringUnion<'small' | 'medium', SwitchPropsSizeOverrides> | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
  /**
   * The value of the component. The DOM API casts this to a string.
   * The browser uses "on" as the default value.
   */
  value?: unknown;
}

export default function Switch(props: SwitchProps): React.JSX.Element;
```

### vendor/src/FormControl/FormControl.d.ts

```ts
import * as React from 'react';

import { SxProps } from '@mui/system';

import { OverridableStringUnion } from '@mui/types';

import { OverridableComponent, OverrideProps } from '../OverridableComponent';

import { Theme } from '../styles';

import { FormControlClasses } from './formControlClasses';

export interface FormControlPropsSizeOverrides {}

export interface FormControlPropsColorOverrides {}

export interface FormControlOwnProps {
  /**
   * The content of the component.
   */
  children?: React.HTMLAttributes<HTMLDivElement>['children'] | undefined;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<FormControlClasses> | undefined;
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   * @default 'primary'
   */
  color?:
    | OverridableStringUnion<
        'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
        FormControlPropsColorOverrides
      >
    | undefined;
  /**
   * If `true`, the label, input and helper text should be displayed in a disabled state.
   * @default false
   */
  disabled?: boolean | undefined;
  /**
   * If `true`, the label is displayed in an error state.
   * @default false
   */
  error?: boolean | undefined;
  /**
   * If `true`, the component will take up the full width of its container.
   * @default false
   */
  fullWidth?: boolean | undefined;
  /**
   * If `true`, the component is displayed in focused state.
   */
  focused?: boolean | undefined;
  /**
   * If `true`, the label is hidden.
   * This is used to increase density for a `FilledInput`.
   * Be sure to add `aria-label` to the `input` element.
   * @default false
   */
  hiddenLabel?: boolean | undefined;
  /**
   * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
   * @default 'none'
   */
  margin?: 'dense' | 'normal' | 'none' | undefined;
  /**
   * If `true`, the label will indicate that the `input` is required.
   * @default false
   */
  required?: boolean | undefined;
  /**
   * The size of the component.
   * @default 'medium'
   */
  size?: OverridableStringUnion<'small' | 'medium', FormControlPropsSizeOverrides> | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
  /**
   * The variant to use.
   * @default 'outlined'
   */
  variant?: 'standard' | 'outlined' | 'filled' | undefined;
}

export interface FormControlTypeMap<
  AdditionalProps = {},
  RootComponent extends React.ElementType = 'div',
> {
  props: AdditionalProps & FormControlOwnProps;
  defaultComponent: RootComponent;
}

declare const FormControl: OverridableComponent<FormControlTypeMap>;

export type FormControlProps<
  RootComponent extends React.ElementType = FormControlTypeMap['defaultComponent'],
  AdditionalProps = {},
> = OverrideProps<FormControlTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
  component?: React.ElementType | undefined;
};
```

### vendor/src/FormGroup/FormGroup.d.ts

```ts
import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import { FormGroupClasses } from './formGroupClasses';

export interface FormGroupProps extends StandardProps<React.HTMLAttributes<HTMLDivElement>> {
  /**
   * The content of the component.
   */
  children?: React.ReactNode;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<FormGroupClasses> | undefined;
  /**
   * Display group of elements in a compact row.
   * @default false
   */
  row?: boolean | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export default function FormGroup(props: FormGroupProps): React.JSX.Element;
```

### vendor/src/FormLabel/FormLabel.d.ts

```ts
import * as React from 'react';

import { SxProps } from '@mui/system';

import { OverridableStringUnion } from '@mui/types';

import { Theme } from '../styles';

import { OverridableComponent, OverrideProps, OverridableTypeMap } from '../OverridableComponent';

import { FormLabelClasses } from './formLabelClasses';

export interface FormLabelPropsColorOverrides {}

export type FormLabelBaseProps = React.LabelHTMLAttributes<HTMLLabelElement>;

export interface FormLabelOwnProps {
  /**
   * The content of the component.
   */
  children?: React.LabelHTMLAttributes<HTMLLabelElement>['children'] | undefined;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<FormLabelClasses> | undefined;
  /**
   * The color of the component.
   * It supports both default and custom theme colors, which can be added as shown in the
   * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
   */
  color?:
    | OverridableStringUnion<
        'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
        FormLabelPropsColorOverrides
      >
    | undefined;
  /**
   * If `true`, the label should be displayed in a disabled state.
   */
  disabled?: boolean | undefined;
  /**
   * If `true`, the label is displayed in an error state.
   */
  error?: boolean | undefined;
  /**
   * If `true`, the label should use filled classes key.
   */
  filled?: boolean | undefined;
  /**
   * If `true`, the input of this label is focused (used by `FormGroup` components).
   */
  focused?: boolean | undefined;
  /**
   * If `true`, the label will indicate that the `input` is required.
   */
  required?: boolean | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
}

export interface FormLabelTypeMap<
  AdditionalProps = {},
  RootComponent extends React.ElementType = 'label',
> {
  props: AdditionalProps & FormLabelBaseProps & FormLabelOwnProps;
  defaultComponent: RootComponent;
}

declare const FormLabel: OverridableComponent<FormLabelTypeMap>;

export interface ExtendFormLabelTypeMap<TypeMap extends OverridableTypeMap> {
  props: TypeMap['props'] & Pick<FormLabelOwnProps, 'filled' | 'color'>;
  defaultComponent: TypeMap['defaultComponent'];
}

export type FormLabelProps<
  RootComponent extends React.ElementType = FormLabelTypeMap['defaultComponent'],
  AdditionalProps = {},
> = OverrideProps<FormLabelTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
  component?: React.ElementType | undefined;
};
```

### vendor/src/FormControlLabel/FormControlLabel.d.ts

```ts
import * as React from 'react';

import { SxProps } from '@mui/system';

import { Theme } from '../styles';

import { InternalStandardProps as StandardProps } from '../internal';

import Typography from '../Typography';

import { FormControlLabelClasses } from './formControlLabelClasses';

import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';

export interface FormControlLabelSlots {
  /**
   * The component that renders the label.
   * This is unused if `disableTypography` is true.
   * @default Typography
   */
  typography: React.ElementType;
}

export type FormControlLabelSlotsAndSlotProps = CreateSlotsAndSlotProps<
  FormControlLabelSlots,
  {
    typography: SlotProps<typeof Typography, {}, FormControlLabelProps>;
  }
>;

export interface FormControlLabelProps
  extends
    StandardProps<React.LabelHTMLAttributes<HTMLLabelElement>, 'children' | 'onChange'>,
    FormControlLabelSlotsAndSlotProps {
  /**
   * If `true`, the component appears selected.
   */
  checked?: boolean | undefined;
  /**
   * Override or extend the styles applied to the component.
   */
  classes?: Partial<FormControlLabelClasses> | undefined;
  /**
   * A control element. For instance, it can be a `Radio`, a `Switch` or a `Checkbox`.
   */
  control: React.ReactElement<unknown, any>;
  /**
   * If `true`, the control is disabled.
   */
  disabled?: boolean | undefined;
  /**
   * If `true`, the label is rendered as it is passed without an additional typography node.
   */
  disableTypography?: boolean | undefined;
  /**
   * Pass a ref to the `input` element.
   */
  inputRef?: React.Ref<any> | undefined;
  /**
   * A text or an element to be used in an enclosing label element.
   */
  label: React.ReactNode;
  /**
   * The position of the label.
   * @default 'end'
   */
  labelPlacement?: 'end' | 'start' | 'top' | 'bottom' | undefined;
  name?: string | undefined;
  /**
   * Callback fired when the state is changed.
   *
   * @param {React.SyntheticEvent} event The event source of the callback.
   * You can pull out the new checked state by accessing `event.target.checked` (boolean).
   */
  onChange?: ((event: React.SyntheticEvent, checked: boolean) => void) | undefined;
  /**
   * If `true`, the label will indicate that the `input` is required.
   */
  required?: boolean | undefined;
  /**
   * The system prop that allows defining system overrides as well as additional CSS styles.
   */
  sx?: SxProps<Theme> | undefined;
  /**
   * The value of the component.
   */
  value?: unknown;
}

export default function FormControlLabel(props: FormControlLabelProps): React.JSX.Element;
```

## Post-install acceptance

Run strict types, production build and real interactions. Check keyboard labels/focus, disabled/error/read-only semantics where natively supported, both themes, narrow screens and reduced motion. Verify callbacks against the real host data; do not declare installation complete from copying a prompt. Initialization fixtures also require server HTML and warning-free hydration.

## Source and license

https://github.com/mui/material-ui/tree/809a7717b4c050ba3f69b75300689f07c050a16e

MIT · @mui/material@9.4.0. Vendor originals and license are preserved. Full original upstream prose remains in vendor/docs and is not represented as fully translated.

---

Index of all JGuang resources: https://jiguang132.com/llms.txt
