A shadcn date picker: a trigger button that opens a shad_calendar() in a
popover. Value contract is identical to shad_calendar().
Usage
shad_date_picker(
inputId,
label = NULL,
value = NULL,
mode = c("single", "range"),
placeholder = "Pick a date",
min = NULL,
max = NULL,
presets = NULL,
caption_layout = c("label", "dropdown", "dropdown-months", "dropdown-years"),
year_range = NULL,
disabled = FALSE,
width = NULL,
class = NULL,
...
)Arguments
- inputId
Input id.
- label
Optional label (wraps in
shad_form_field()).- value
Initial selection: a
Date/character (single) or length-2Date/character (range).- mode
"single"(default) or"range".- placeholder
Trigger text shown when nothing is selected.
- min, max
Selectable bounds (inclusive),
Date/character.- presets
Optional quick-range rail, only valid with
mode = "range". A named list; names are the button labels and each value is either a keyword ("today","yesterday","this-week","this-month","last-month","this-year"), an integerNmeaning the lastNdays, or a length-2Datevector giving an explicit start and end.shad_date_presets()returns a ready-made set.- caption_layout
Header style:
"label"(default, month and year as text),"dropdown"(both as selects),"dropdown-months"or"dropdown-years". Use a dropdown when the user has to travel years, such as a date of birth.- year_range
Length-2 numeric bounding the year dropdown, e.g.
c(1900, 2025). Defaults to the years ofmin/maxwhen given, otherwise 100 years back and 10 forward.- disabled
If
TRUE, disables the control.- width
CSS width.
- class
Extra CSS classes.
- ...
Extra attributes on the calendar root.
See also
Other shadshiny tier-2 components:
shad_calendar(),
shad_checkbox(),
shad_combobox(),
shad_date_presets(),
shad_form_field(),
shad_input(),
shad_input_group(),
shad_input_otp(),
shad_native_select(),
shad_radio_group(),
shad_select(),
shad_slider(),
shad_switch(),
shad_textarea(),
shad_toggle(),
shad_toggle_group()
Examples
shad_date_picker("d", label = "Date")
#> <div class="shad-form-field" data-shad="form-field">
#> <label class="shad-label">Date</label>
#> <div class="shad-date-picker" data-shad="date-picker" id="d">
#> <button type="button" class="shad-date-picker__trigger" data-placeholder>
#> <svg class="shad-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>
#> <span class="shad-date-picker__value">Pick a date</span>
#> </button>
#> <div class="shad-date-picker__content shad-anim-pop" hidden>
#> <div class="shad-calendar" data-shad="calendar" data-mode="single" data-week-start="0"></div>
#> </div>
#> </div>
#> <p class="shad-form-field__error" hidden></p>
#> </div>
shad_date_picker("range", mode = "range")
#> <div class="shad-date-picker" data-shad="date-picker" id="range">
#> <button type="button" class="shad-date-picker__trigger" data-placeholder>
#> <svg class="shad-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>
#> <span class="shad-date-picker__value">Pick a date</span>
#> </button>
#> <div class="shad-date-picker__content shad-anim-pop" hidden>
#> <div class="shad-calendar" data-shad="calendar" data-mode="range" data-week-start="1"></div>
#> </div>
#> </div>
shad_date_picker("dob", label = "Date of birth", caption_layout = "dropdown")
#> <div class="shad-form-field" data-shad="form-field">
#> <label class="shad-label">Date of birth</label>
#> <div class="shad-date-picker" data-shad="date-picker" id="dob">
#> <button type="button" class="shad-date-picker__trigger" data-placeholder>
#> <svg class="shad-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M8 2v4"/><path d="M16 2v4"/><rect width="18" height="18" x="3" y="4" rx="2"/><path d="M3 10h18"/></svg>
#> <span class="shad-date-picker__value">Pick a date</span>
#> </button>
#> <div class="shad-date-picker__content shad-anim-pop" hidden>
#> <div class="shad-calendar" data-shad="calendar" data-mode="single" data-week-start="0" data-caption-layout="dropdown"></div>
#> </div>
#> </div>
#> <p class="shad-form-field__error" hidden></p>
#> </div>