Calendar

Calendar component (Phlex) A date picker calendar with support for single, range, and multiple selection

Examples

Default

A date picker calendar built with date-fns and Stimulus.

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar" %>
</div>

With Selected Date

Calendar with a pre-selected date.

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", selected: Date.today %>
</div>

Date Range

Select a start and end date.

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", mode: :range, selected: Date.today..(Date.today + 7) %>
</div>

Multiple Months

Display 2 months side by side.

Su Mo Tu We Th Fr Sa
Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", number_of_months: 2 %>
</div>

Multiple Months with Range

Date range selection with 2 months displayed (hover to preview range).

Su Mo Tu We Th Fr Sa
Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", mode: :range, number_of_months: 2 %>
</div>

With Dropdowns (Native)

Month/Year dropdown navigation using native HTML selects.

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", show_dropdowns: true %>
</div>

With Dropdowns (UI Select)

Month/Year dropdown navigation using our custom UI Select component.

January
February
March
April
May
June
July
August
September
October
November
December
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", show_dropdowns: true, use_native_select: false %>
</div>

With Min/Max Dates

Restricted date range (next 30 days only).

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", min_date: Date.today, max_date: Date.today + 30.days %>
</div>

Range With Min/Max Days

Range selection constrained to 3-7 days (hover over dates to see preview).

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", mode: :range, min_range_days: 3, max_range_days: 7 %>
</div>

Range With Disabled Dates

Range cannot include disabled dates (weekends disabled).

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", mode: :range, exclude_disabled: true, disabled_dates: weekend_dates %>
</div>

Week Starts Monday

European-style calendar starting on Monday.

Mo Tu We Th Fr Sa Su
<div class="rounded-md border">
  <%= render "ui/calendar", week_starts_on: 1 %>
</div>

Localization (pt-BR)

Calendar with Portuguese (Brazil) locale for month and weekday names.

Su Mo Tu We Th Fr Sa
<div class="rounded-md border">
  <%= render "ui/calendar", locale: "pt-BR" %>
</div>

Features

  • Keyboard navigation
  • Form integration
  • Disabled state support
  • ARIA attributes for accessibility
  • Keyboard navigation with arrow keys
  • Click outside to close
  • Animation support

API Reference

Calendar

Parameters

NameTypeDefaultDescription
modeSymbol:singleThe mode
selectedStringnilThe selected
monthStringDate.todayThe month
number_of_monthsInteger1The number of months
week_starts_onInteger0The week starts on
localeStringen-USThe locale
min_dateStringnilThe min date
max_dateStringnilThe max date
disabled_datesArray[]The disabled dates
show_outside_daysBooleantrueThe show outside days
fixed_weeksBooleanfalseThe fixed weeks
show_dropdownsBooleanfalseThe show dropdowns
year_rangeInteger100The year range
min_range_daysInteger0The min range days
max_range_daysInteger0The max range days
exclude_disabledBooleanfalseThe exclude disabled
use_native_selectBooleantrueThe use native select
nameStringnilForm field name

Keyboard Shortcuts

KeyDescription
EnterActivates the focused element
SpaceActivates the focused element
ArrowDownMoves focus to next item
ArrowUpMoves focus to previous item
ArrowLeftMoves focus left or decreases value
ArrowRightMoves focus right or increases value
HomeMoves focus to first item
EndMoves focus to last item
PageUpMoves focus up by page
PageDownMoves focus down by page

JavaScript

Stimulus Controller

ui--calendar

Values

NameTypeDescription
modeStringThe mode

Actions

initializeLocalepreviousMonthnextMonthpreviousYearnextYeargoToMonthgoToYeargoToTodaydispatchMonthChangeannounceMonthChangeannounceSelectionselectDateselectRangehasDisabledDatesInRangetoggleDateisInRangePreviewisRangePreviewStartisRangePreviewEndanimateMonthTransitionisSelectedisDisabledisInRangeisRangeStartisRangeEndmoveFocusselectFocusedDaterestoreFocusnavigateAndFocusmoveToStartOfWeekmoveToEndOfWeek