Calendar

The calendar component is a web component that displays a calendar with the ability to select a date.

Overview

The calendar component provides a visual date picker interface with full keyboard navigation support. It's built using the dayjs library for date manipulation and offers comprehensive customization options including date ranges, localization, and custom disabled date functions.

Examples

The calendar component is using the dayjs library to handle dates. The best way to use the calendar component if you are using the dayjs library in your project. The component settings are properties, not attributes, so you have to set them in JavaScript.

Default

The calendar component can be used to select a date. By default, it displays the current month and no date is selected.

<dap-ds-calendar></dap-ds-calendar>
Value

The value property can be used to set the selected date. The calendar will automatically navigate to the month containing the selected date.

HTML

Js

const calendar = document.querySelector('dap-ds-calendar')
calendar.value = dayjs().add(1, 'day')
Current date

The currentDate property can be used to set the currently visible month and year. This is useful for displaying a specific month without selecting a date.

HTML

Js

const calendar = document.querySelector('dap-ds-calendar')
calendar.currentDate = new Date('2022-08-15T22:00:00.000Z')
calendar.value = dayjs('2022-08-13T22:00:00.000Z')
Min date, Max date

The minDate and maxDate properties can be used to restrict the selectable date range. Dates outside this range will be disabled and navigation will be limited to the allowed range.

In this example, the minDate is set to the previous month and the maxDate is set to the next month, so navigation is restricted to a 3-month window.

HTML

Js

const calendar = document.querySelector('dap-ds-calendar')
calendar.minDate = dayjs().add(-1, 'month')
calendar.maxDate = dayjs().add(1, 'month')
calendar.value = dayjs()
Disabled date

The disabledDate property accepts a function that determines if a specific date should be disabled. The function receives a Dayjs object and should return true if the date should be disabled.

In this example, the disabledDate function disables weekends (Saturday and Sunday).

HTML

JS

const calendar = document.querySelector('dap-ds-calendar')
calendar.disabledDate = (date) => date.day() === 0 || date.day() === 6
Localization

The locale property can be used to set the locale of the calendar, affecting month names, weekday names, and date formatting. The component automatically detects the browser's locale if not specified.

Supported locales are en (English) and hu (Hungarian).

HTML

Hungarian locale

English locale

Js

const calendar = document.querySelector('dap-ds-calendar')
calendar.locale = 'hu'
calendar.value = dayjs().add(1, 'day')

Accessibility Features
  • ARIA Labels: Navigation buttons and select controls have descriptive labels
  • Keyboard Navigation: Full keyboard support for date selection and navigation
  • Screen Reader Support: Proper ARIA attributes for grid navigation
  • Focus Management: Clear focus indicators and logical tab order
  • Disabled State: Proper ARIA attributes for disabled dates
Best Practices
  1. Use with dayjs: The component is designed to work with dayjs objects for optimal performance
  2. Set reasonable date ranges: Use minDate and maxDate to prevent users from navigating to irrelevant dates
  3. Provide clear labels: Use descriptive labels for better accessibility
  4. Handle events: Always listen for dds-change events to update your application state
  5. Consider locale: Set the appropriate locale for your users' region
Common Patterns Date Range Validation
const calendar = document.querySelector('dap-ds-calendar')
calendar.minDate = dayjs().subtract(1, 'year')
calendar.maxDate = dayjs().add(1, 'year')
Business Days Only
const calendar = document.querySelector('dap-ds-calendar')
calendar.disabledDate = (date) => {
  const day = date.day()
  return day === 0 || day === 6 // Disable weekends
}
Dynamic Locale Switching
const calendar = document.querySelector('dap-ds-calendar')
document.querySelector('#locale-selector').addEventListener('change', (e) => {
  calendar.locale = e.target.value
})
Importing
import { DapDSCalendar } from 'dap-design-system/dist/dds'
Importing React
import { DapDSCalendarReact } from 'dap-design-system/dist/react'
Attributes
PropertyTypeDefaultDescription
valueDayjsThe value of the calendar.
currentDateDayjsdayjs()The current visible date of the calendar. Only the month and year are considered.
minDateDayjsdayjs().subtract(50, 'year')The minimum date of the calendar. Only the month and year are considered.
maxDateDayjsdayjs().add(50, 'year')The maximum date of the calendar. Only the month and year are considered.
disabledDateFunction() => falseThe function to determine if the date is disabled.
localestringdayjs.locale()The locale of the calendar.
Slots
NameDescription
(default)The content of the calendar.
Events
Event NameDescriptionType
dds-changeFired when the calendar value changes.{value: Dayjs }
CSS Parts
Part NameDescription
baseThe main calendar container.
headerThe header of the calendar.
bodyThe body of the calendar.
CSS Custom Properties
Property NameDescription
--dds-calendar-displayThe display property of the calendar container. Default is flex.
--dds-calendar-isolationThe isolation property of the calendar. Default is isolate.
--dds-calendar-block-displayThe display property of the calendar block. Default is block.
--dds-calendar-transitionThe transition property for the calendar. Default is 'all 0.2s ease-in-out'.
--dds-calendar-header-displayThe display property of the calendar header. Default is grid.
--dds-calendar-header-grid-flowThe grid-auto-flow property of the calendar header. Default is column.
--dds-calendar-header-widthThe width of the calendar header. Default is 100%.
--dds-calendar-header-gapThe gap between header items. Default is the design system's spacing-100.
--dds-calendar-select-min-heightThe minimum height of the select trigger. Default is auto.
--dds-calendar-select-max-heightThe maximum height of the select trigger. Default is 32px.
--dds-calendar-select-paddingThe padding of the select trigger. Default is the design system's spacing-200.
--dds-calendar-select-border-radiusThe border radius of the select trigger. Default is the design system's radius-rounded.
--dds-calendar-select-border-colorThe border color of the select trigger. Default is the design system's border-neutral-transparent-interactive.
--dds-calendar-select-backgroundThe background color of the select trigger. Default is the design system's button-subtle-background-enabled.
--dds-calendar-select-colorThe text color of the select trigger. Default is the design system's button-subtle-text-enabled.
--dds-calendar-select-font-sizeThe font size of the select trigger. Default is the design system's font-sm.
--dds-calendar-select-font-styleThe font style of the select trigger. Default is normal.
--dds-calendar-select-font-weightThe font weight of the select trigger. Default is the design system's font-weight-bold.
--dds-calendar-nav-button-marginThe margin of the navigation buttons. Default is the design system's spacing-200.
--dds-calendar-nav-button-colorThe color of the navigation button icons. Default is the design system's button-subtle-icon-enabled.
Components Calendar cell <dap-ds-calendar-cell/> Attributes
PropertyTypeDefaultDescription
valueDayjsThe value of the calendar cell.
selectedbooleanfalseWhether the calendar cell is selected.
disabledDaybooleanfalseWhether the calendar cell is disabled.
todaybooleanfalseWhether the calendar cell is today.
outOfRangebooleanfalseWhether the calendar cell is out of range.
headerbooleanfalseWhether the calendar cell is a date header.
focusedbooleanfalseWhether the calendar cell is focused.
Slots
NameDescription
(default)The content of the calendar cell.
Events

No custom events available.

CSS Parts
Part NameDescription
baseThe main calendar cell container.
today-markThe today mark of the calendar cell.
CSS Custom Properties

No CSS custom properties available.