# Label

> Names a form control and focuses it when clicked.

A label names a form control, and clicking it moves focus to that control.

## When to use

- Give every input, select and checkbox a visible label.
- Put labels above inputs and selects, and beside checkboxes.
- Keep labels short; put guidance in a hint below the field.

_Live preview of the React and Vue versions: https://design.sosialoka.tech/components/label/_

## Anatomy

1. Label text
2. Required mark
3. The control it names

One line of `text-sm` medium text in `foreground`. A disabled control dims its label too.

## Variants

There is one style.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `htmlFor` | `for` | `label` on the field | string | none | The `id` of the control it names. |

## Code

**React**
```tsx
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export default function LabelDemo() {
  return (
    <div className="grid w-full max-w-sm gap-2">
      <Label htmlFor="label-demo-name">Nama lengkap</Label>
      <Input id="label-demo-name" />
    </div>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
</script>

<template>
  <div class="grid w-full max-w-sm gap-2">
    <Label for="label-demo-name-vue">Nama lengkap</Label>
    <Input id="label-demo-name-vue" />
  </div>
</template>
```

**Flutter**
```dart
// Flutter has no separate label widget: form fields take a `label`.
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

class LabelDemo extends StatelessWidget {
  const LabelDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return ConstrainedBox(
      constraints: const BoxConstraints(maxWidth: 384),
      child: ShadInputFormField(
        id: 'name',
        label: const Text('Nama lengkap'),
      ),
    );
  }
}
```

## Install

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/label.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/label.json
```

## Accessibility

- Renders a native `label`, so clicking it focuses the control.
- Flutter has no separate label widget; pass `label` to the form field.
