# Level switch

> One row's access level (No · Read · Edit): native radios in a fieldset, posts without JavaScript, selected in the row's product accent.

- Group: Form controls
- Status: stable
- Aliases: access-level, permission-level
- HTML page: https://design.ipmnx.com/components/level-switch/
- Spec: https://design.ipmnx.com/design/#nx-level-switch

## Preview

**ordNX access for an assistant** Edit is shown but disabled when the connection does not allow writing.

```html
<fieldset class="nx-level" data-nx-product="ord">
  <legend class="nx-sr-only">ordNX</legend>
  <span class="nx-level__track">
    <label class="nx-level__opt">
      <input type="radio" name="demo-level" value="none"/>
      <span>No</span>
    </label>
    <label class="nx-level__opt">
      <input type="radio" name="demo-level" value="read" checked/>
      <span>Read</span>
    </label>
    <label class="nx-level__opt"
        title="Not allowed on this connection">
      <input type="radio" name="demo-level" value="write" disabled/>
      <span>Edit</span>
    </label>
  </span>
</fieldset>
```

```tsx
<NxLevelSwitch
  name="product:ordnx"
  label="ordNX"
  product="ord"
  defaultValue="read"
  options={[
    { value: "none", label: "No" },
    { value: "read", label: "Read" },
    {
      value: "write",
      label: "Edit",
      disabled: true,
      title: "Not allowed on this connection",
    },
  ]}
/>
```

## API

### React props (NxKit)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `name` | `string` |   | yes | Form field name. |
| `label` | `ReactNode` |   | yes | Group name (legend). |
| `options` | `{ value; label; disabled?; title? }[]` |   | yes | Levels, lowest first. |
| `value / defaultValue` | `T` |   |   | Controlled or uncontrolled selection. |
| `product` | `NxProduct` |   |   | Accent of the selected option. |
| `hideLabel` | `boolean` | `true` |   | Visually hide the legend. |

### Classes

| Class | Description |
| --- | --- |
| `.nx-level` | Fieldset |
| `.nx-level__track` | Segmented track |
| `.nx-level__opt` | One level; checked uses accent-100 / accent-700 |

## Accessibility

- fieldset + legend + native radios: arrow keys move, the group is named, disabled levels stay visible with a title.

## Do / Don't

- Do: Disable a level that is not available and say why.
- Don't hide it: the person must see that it exists.

## Related

- [Segmented control](https://design.ipmnx.com/components/segmented.md)
- [Radio](https://design.ipmnx.com/components/radio.md)

---

Source: registry.js (NX Design System)
