# Date Picker

> Tombol yang membuka kalender dan menampilkan tanggal yang dipilih.

Date Picker adalah kolom form yang membuka [Calendar](https://design.sosialoka.tech/id/components/calendar/) di popover dan menampilkan tanggal yang dipilih, misalnya tanggal rilis.

## Kapan dipakai

- Pakai untuk satu tanggal di form yang dekat dengan hari ini: tanggal rilis, tenggat.
- Di form panjang yang tanggalnya sudah diketahui pasti, misalnya tanggal lahir atau tanggal kontrak bertahun-tahun lalu, input tanggal native (`<input type="date">`) lebih cepat diketik.
- Tampilkan tanggal sebagai `14 Nov 2026`. Kirim ke backend dalam format ISO `2026-11-14`, jangan teks yang tampil.

_Pratinjau langsung versi React dan Vue: https://design.sosialoka.tech/id/components/date-picker/_

## Anatomi

1. Pemicu yang menampilkan tanggal
2. Ikon kalender
3. Kalender di popover
4. Hari terpilih

[Button](https://design.sosialoka.tech/id/components/button/) `outline` dengan ikon kalender dan tanggalnya, atau placeholder "Pilih tanggal" berwarna `muted-foreground`. Klik membuka kalender di [Popover](https://design.sosialoka.tech/id/components/popover/); memilih hari menutupnya.

## Props

| React | Vue | Flutter | Tipe | Bawaan | Kegunaan |
| --- | --- | --- | --- | --- | --- |
| `value`, `onValueChange` | `v-model` | `ShadDatePicker onChanged` | `Date` / `DateValue` / `DateTime` | tidak ada | Tanggal yang dipilih. |
| `placeholder` | `placeholder` | `placeholder` | teks | `Pick a date` | Tampil sebelum tanggal dipilih, misalnya "Pilih tanggal". |
| `disabled` | `disabled` | `enabled: false` | boolean | `false` | Menonaktifkan kolom. |
| `locale` | `locale` | `locale` aplikasi | lokal | Inggris (en-GB) | Nama bulan, dan cara tanggal ditulis. Untuk bahasa Indonesia, `id` dari `react-day-picker/locale` atau `"id-ID"`. |
| `dateFormat` | | `formatDate` | teks / fungsi | tanggal pendek lokal (`14 Aug 2026`; `14 Agu 2026` dalam bahasa Indonesia) | Pola date-fns, kalau tanggal perlu bentuk lain. |

## Kode

**React**
```tsx
import { useState } from "react"
import { id } from "react-day-picker/locale"
import { DatePicker } from "@/components/ui/date-picker"

export default function DatePickerDemo() {
  const [date, setDate] = useState<Date>()
  return <DatePicker locale={id} value={date} onValueChange={setDate} placeholder="Pilih tanggal" className="w-56" />
}
```

**Vue**
```vue
<script setup lang="ts">
import type { DateValue } from "@internationalized/date"
import { shallowRef } from "vue"
import { DatePicker } from "@/components/ui/date-picker"

const date = shallowRef<DateValue>()
</script>

<template>
  <DatePicker v-model="date" locale="id-ID" placeholder="Pilih tanggal" class="w-56" />
</template>
```

**Flutter**
```dart
// A date field that opens a calendar. Dates read "15 Nov 2026"; the app runs with locale: Locale('id').
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

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

  @override
  Widget build(BuildContext context) {
    return ShadDatePicker(
      width: 256,
      placeholder: const Text('Pilih tanggal'),
      initialMonth: DateTime(2026, 11),
      weekStartsOn: 1,
      formatDate: (date) => DateFormat('d MMM yyyy', 'id').format(date),
    );
  }
}
```

## Instal

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

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

## Aksesibilitas

- Saat dibuka, fokus langsung di hari yang dipilih, atau hari ini, jadi tombol panah bisa langsung dipakai.
- Enter memilih hari dan menutup popover; Escape menutupnya. Keduanya mengembalikan fokus ke tombol.
- Beri kolom ini label yang terlihat dengan [Field](https://design.sosialoka.tech/id/components/field/), misalnya "Tanggal rilis".
