# Date Picker

> A button that opens a calendar and shows the chosen date.

A date picker is a form field that opens a [Calendar](https://design.sosialoka.tech/components/calendar/) in a popover and shows the chosen date, such as a release date.

## When to use

- Use it for one date in a form, near today: a release date, a deadline.
- In long forms where people know the exact date, such as a birth date or a contract date years ago, a native date input (`<input type="date">`) is faster to type.
- Show the date as `14 Nov 2026`. Send it to the backend as ISO `2026-11-14`, never as the displayed text.

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

## Anatomy

1. Trigger showing the date
2. Calendar icon
3. Calendar in a popover
4. Selected day

An `outline` [Button](https://design.sosialoka.tech/components/button/) with a calendar icon and the date, or the placeholder "Pilih tanggal" in `muted-foreground`. Clicking it opens the calendar in a [Popover](https://design.sosialoka.tech/components/popover/); picking a day closes it.

## Props

| React | Vue | Flutter | Type | Default | Use |
| --- | --- | --- | --- | --- | --- |
| `value`, `onValueChange` | `v-model` | `ShadDatePicker onChanged` | `Date` / `DateValue` / `DateTime` | none | The chosen date. |
| `placeholder` | `placeholder` | `placeholder` | text | `Pick a date` | Shown before a date is picked, such as "Pilih tanggal". |
| `disabled` | `disabled` | `enabled: false` | boolean | `false` | Turns the field off. |
| `locale` | `locale` | the app's `locale` | locale | English (en-GB) | Month names, and how the date reads. For Indonesian, `id` from `react-day-picker/locale` or `"id-ID"`. |
| `dateFormat` | | `formatDate` | text / function | the locale's short date (`14 Aug 2026`) | A date-fns pattern, when the date needs another shape. |

## Code

**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),
    );
  }
}
```

## Install

**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
```

## Accessibility

- Opening the picker puts focus on the chosen day, or today, so the arrow keys work straight away.
- Enter picks the day and closes the popover; Escape closes it. Either way, focus goes back to the button.
- Give the field a visible label with [Field](https://design.sosialoka.tech/components/field/), such as "Tanggal rilis".
