---
title: "Date Picker"
description: "Choose a constrained date range with preset shortcuts."
---

# Date Picker

Choose a constrained date range with preset shortcuts.

## Installation

Install the shared package once in your Exact app. This version is a beta.

```sh
bun add --exact @rightui/ui@0.4.0-beta.4
```

Or choose another package manager:

```sh
npm install --save-exact @rightui/ui@0.4.0-beta.4
pnpm add --save-exact @rightui/ui@0.4.0-beta.4
yarn add --exact @rightui/ui@0.4.0-beta.4
```

Exact compilation uses Bun 1.4.2. Register Geist and Newsreader, declare the font marker and add the root provider using [Installation](/docs/installation).

### Manual source setup

Install an editable copy of the complete package:

```sh
mkdir -p vendor/rightui vendor/rightui-ui
npm pack @rightui/ui@0.4.0-beta.4 --pack-destination vendor/rightui
tar -xzf ./vendor/rightui/rightui-ui-0.4.0-beta.4.tgz -C vendor/rightui-ui --strip-components=1
bun add file:./vendor/rightui-ui
```

Keep package.json, the Contract files, ui.tamber, assets and licenses together.

### Import

```contract
use DatePicker, DateRangePicker, DateRangePreset from "@rightui/ui"
```

## Usage

Import DatePicker, DateRangePicker from @rightui/ui. Store its value in state and update it through the provided action callback.

## Example

```contract
use FontWeights from "@rightui/ui"
use uiFontFamily, DatePicker from "@rightui/ui"
use DateRangePicker, DateRangePreset from "@rightui/ui"

component Demo
  props
    width: number
    reduced: bool
  inject
    uiWeights: FontWeights
    uiFont: string
  derive narrow = width < 600
  state low = "2026-03-09"
  state high = "2026-03-12"
  action chooseRange(start: string, finish: string)
    low = start
    high = finish
  state selectedDate = "2026-03-09"
  action chooseDate(v: string)
    selectedDate = v
  view
    column gap="ui.space-16" min-width=0 max-width="100%"
      DateRangePicker(id="dates-range", low=low, high=high, initialYear=2026, initialMonth=3, minimum="2026-03-05", maximum="2026-05-25", disabledDates=["2026-03-17"], disabledWeekends=true, disabled=false, narrow=narrow, reduced=reduced, presets=[DateRangePreset(label="March 9–12", low="2026-03-09", high="2026-03-12"), DateRangePreset(label="April 6–10", low="2026-04-06", high="2026-04-10")], change=chooseRange)
      text "Single date" font-weight=uiWeights.semibold font-family=uiFontFamily(uiFont) data-rightui-font="body"
      DatePicker(id="date-single-picker", value=selectedDate, initialYear=2026, initialMonth=3, disabled=false, change=chooseDate)

```

## API Reference

| Property | Type |
| --- | --- |
| DatePicker.id | string |
| DatePicker.value | string |
| DatePicker.initialYear | number |
| DatePicker.initialMonth | number |
| DatePicker.disabled | bool |
| DatePicker.change | action |
| DateRangePicker.id | string |
| DateRangePicker.low | string |
| DateRangePicker.high | string |
| DateRangePicker.initialYear | number |
| DateRangePicker.initialMonth | number |
| DateRangePicker.minimum | string |
| DateRangePicker.maximum | string |
| DateRangePicker.disabledDates | string[] |
| DateRangePicker.disabledWeekends | bool |
| DateRangePicker.disabled | bool |
| DateRangePicker.narrow | bool |
| DateRangePicker.reduced | bool |
| DateRangePicker.presets | DateRangePreset[] |
| DateRangePicker.change | action |

## Source

File: packages/ui/date-picker.contract

```contract
use FontWeights from "./typography-context.contract"
use uiFontFamily from "./typography-context.contract"
use Calendar from "./calendar.contract"
use Control from "./styles.contract"
component DatePicker
  props
    id: string
    value: string
    initialYear: number
    initialMonth: number
    disabled: bool
    change: action
  inject
    uiWeights: FontWeights
    uiFont: string
  state opened = false
  state year = initialYear
  state month = initialMonth
  action toggle
    if not disabled
      if opened
        hidePopover(id + "-popup")
      else
        year = match parseNumber(value.slice(0, 4)) { case some(y) => max(1, min(9999, floor(y))), case none => initialYear }
        month = match parseNumber(value.slice(5, 7)) { case some(m) => max(1, min(12, floor(m))), case none => initialMonth }
        opened = true
        showPopover(id + "-popup", source=id)
  action changeMonth(y: number, m: number)
    year = y
    month = m
  action toggled(e: ToggleEvent)
    opened = e.newState == "open"
  action selected(v: string)
    change(v)
    hidePopover(id + "-popup")
    focus(id)
  action triggerKeys(k: string)
    if k == "Enter" or k == " "
      preventDefault()
      toggle()
    else if k == "ArrowDown"
      preventDefault()
      if not opened
        toggle()
  action keys(k: string)
    if k == "Escape"
      hidePopover(id + "-popup")
      focus(id)
  view
    column min-width="0px"
      button id=id testId=id class=Control font-weight=uiWeights.medium press=toggle key=triggerKeys disabled=disabled aria-expanded=opened aria-controls=(id + "-popup") aria-haspopup="dialog"
        display="flex" align-items="center" gap="ui.space-8" padding="ui.space-8 ui.space-12" width="15rem" max-width="100%" border-width="ui.border-width" border-style="solid" border-color="ui.border" background-color="ui.surface" color=(value == "" ? "ui.muted-foreground" : "ui.foreground")
        svg width="ui.space-16" height="ui.space-16" viewBox="0 0 24 24" fill="none" stroke="ui.foreground" stroke-width="ui.stroke-standard" aria-hidden=true
          rect x=3 y=5 width=18 height=16 rx=2
          path d="M16 3v4M8 3v4M3 11h18"
        text (value == "" ? "Pick a date" : value) font-family=uiFontFamily(uiFont) data-rightui-font="body"
      if opened
        column id=(id + "-popup") testId=(id + "-popup") popover="auto" toggle=toggled key=keys role="dialog" aria-label="Choose a date" tabindex=-1
          position-area="bottom" position-try-fallbacks="flip-block, flip-inline" max-width="calc(100vw - ui.space-32)" max-height="calc(100vh - ui.space-32)" overflow="auto" margin="ui.space-4" padding="0px" border-width="ui.border-width" border-style="solid" border-color="ui.border" border-radius="ui.radius-popover" background-color="ui.surface"
          Calendar(id=id + "-calendar", year=year, month=month, changeMonth=changeMonth, value=value, end="", mode="single", disabled=disabled, change=selected)

```
