The calendar component is a web component that displays a calendar with the ability to select a date.
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.
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.
The calendar component can be used to select a date. By default, it displays the current month and no date is selected.
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')
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')
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()
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
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')
- 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
- Use with dayjs: The component is designed to work with dayjs objects for optimal performance
- Set reasonable date ranges: Use
minDateandmaxDateto prevent users from navigating to irrelevant dates - Provide clear labels: Use descriptive labels for better accessibility
- Handle events: Always listen for
dds-changeevents to update your application state - Consider locale: Set the appropriate locale for your users' region
const calendar = document.querySelector('dap-ds-calendar')
calendar.minDate = dayjs().subtract(1, 'year')
calendar.maxDate = dayjs().add(1, 'year')
const calendar = document.querySelector('dap-ds-calendar')
calendar.disabledDate = (date) => {
const day = date.day()
return day === 0 || day === 6 // Disable weekends
}
const calendar = document.querySelector('dap-ds-calendar')
document.querySelector('#locale-selector').addEventListener('change', (e) => {
calendar.locale = e.target.value
})
import { DapDSCalendar } from 'dap-design-system'
import { DapDSCalendarReact } from 'dap-design-system/react'
For optimal bundle sizes, use the tree-shakeable import syntax:
import { DapDSCalendar } from 'dap-design-system/components'
| Property | Type | Default | Description |
|---|---|---|---|
mode | 'single', 'range' | 'single' | The mode of the calendar - single date or range selection. |
hideAdjacentMonths | boolean | false | Whether to hide dates from adjacent months (previous/next) in the calendar grid. When not explicitly set, defaults to false for single mode and true for range mode. |
value | Dayjs | The value of the calendar. | |
rangeStart | Dayjs | The start date of the range selection (only used in range mode). | |
rangeEnd | Dayjs | The end date of the range selection (only used in range mode). | |
currentDate | Dayjs | dayjs() | The current visible date of the calendar. Only the month and year are considered. |
minDate | Dayjs | dayjs().subtract(50, 'year') | The minimum date of the calendar. Only the month and year are considered. |
maxDate | Dayjs | dayjs().add(50, 'year') | The maximum date of the calendar. Only the month and year are considered. |
disabledDate | Function | () => false | The function to determine if the date is disabled. |
locale | 'hu', 'en' , 'de' | dayjs.locale() | The locale of the calendar. |
| Name | Description |
|---|---|
(default) | The content of the calendar. |
| Event Name | Description | Type |
|---|---|---|
dds-change | Fired when the calendar value changes. | {value: Dayjs } |
| Part Name | Description |
|---|---|
base | The main calendar container. |
calendar-header | The header of the calendar. |
body | The body of the calendar. |
calendar-grid-header | The header of the calendar grid. |
calendar-grid-header-cell | The header cell of the calendar grid. |
calendar-grid-cell | The cell of the calendar grid. |
calendar-header-button-prev | The previous month button of the calendar header. |
calendar-header-button-next | The next month button of the calendar header. |
calendar-header-year-select | The year select of the calendar header. |
calendar-header-month-select | The month select of the calendar header. |
You can style CSS parts using the ::part() pseudo-element selector:
/* Target a specific part */
.my-custom-dap-ds-calendar::part(base) {
/* Your custom styles */
}
/* Target multiple parts */
.my-custom-dap-ds-calendar::part(base),
.my-custom-dap-ds-calendar::part(calendar-header) {
/* Shared styles */
}
Example usage:
<dap-ds-calendar class="my-custom-dap-ds-calendar">
Calendar
</dap-ds-calendar>
.my-custom-dap-ds-calendar::part(base) {
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
CSS parts allow you to style internal elements of the component while maintaining encapsulation. Learn more in our styling guide.
| Property Name | Description |
|---|---|
--dds-calendar-display | The display property of the calendar container (default: flex) |
--dds-calendar-isolation | The isolation property of the calendar (default: isolate) |
--dds-calendar-block-display | The display property of the calendar block (default: block) |
--dds-calendar-transition | The transition property for the calendar (default: all 0.2s ease-in-out) |
--dds-calendar-header-display | The display property of the calendar header (default: grid) |
--dds-calendar-header-grid-flow | The grid-auto-flow property of the calendar header (default: column) |
--dds-calendar-header-width | The width of the calendar header (default: 100%) |
--dds-calendar-header-gap | The gap between header items (default: var(--dds-spacing-100)) |
--dds-calendar-select-min-height | The minimum height of the select trigger (default: auto) |
--dds-calendar-select-max-height | The maximum height of the select trigger (default: 32px) |
--dds-calendar-select-padding | The padding of the select trigger (default: var(--dds-spacing-200)) |
--dds-calendar-select-border-radius | The border radius of the select trigger (default: var(--dds-radius-rounded)) |
--dds-calendar-select-border-color | The border color of the select trigger (default: var(--dds-border-neutral-transparent-interactive)) |
--dds-calendar-select-background | The background color of the select trigger (default: var(--dds-button-subtle-background-enabled)) |
--dds-calendar-select-color | The text color of the select trigger (default: var(--dds-button-subtle-text-enabled)) |
--dds-calendar-select-font-size | The font size of the select trigger (default: var(--dds-font-sm)) |
--dds-calendar-select-font-style | The font style of the select trigger (default: normal) |
--dds-calendar-select-font-weight | The font weight of the select trigger (default: var(--dds-font-weight-bold)) |
--dds-calendar-nav-button-margin | The margin of the navigation buttons (default: var(--dds-spacing-200)) |
--dds-calendar-nav-button-color | The color of the navigation button icons (default: var(--dds-button-subtle-icon-enabled)) |
CSS custom properties (CSS variables) can be set directly on the component or in your stylesheet:
Method 1: Inline styles (Quick customization)
<dap-ds-calendar
style="--dds-calendar-display: value; --dds-calendar-isolation: value;">
Calendar
</dap-ds-calendar>
Method 2: CSS classes (Reusable styles)
.my-custom-dap-ds-calendar {
--dds-calendar-display: value;
--dds-calendar-isolation: value;
--dds-calendar-block-display: value;
}
<dap-ds-calendar class="my-custom-dap-ds-calendar">
Calendar
</dap-ds-calendar>
Method 3: Global theme customization
/* Apply to all instances */
dap-ds-calendar {
--dds-calendar-display: value;
--dds-calendar-isolation: value;
}
CSS custom properties inherit through the Shadow DOM, making them perfect for theming. Changes apply immediately without rebuilding.
| Property | Type | Default | Description |
|---|---|---|---|
value | Dayjs | The value of the calendar cell. | |
selected | boolean | false | Whether the calendar cell is selected. |
disabledDay | boolean | false | Whether the calendar cell is disabled. |
today | boolean | false | Whether the calendar cell is today. |
outOfRange | boolean | false | Whether the calendar cell is out of range. |
header | boolean | false | Whether the calendar cell is a date header. |
focused | boolean | false | Whether the calendar cell is focused. |
rangestart | boolean | false | Whether the calendar cell is the start of a range. |
rangeend | boolean | false | Whether the calendar cell is the end of a range. |
inrange | boolean | false | Whether the calendar cell is in the middle of a range. |
locale | 'hu', 'en' , 'de' | dayjs.locale() | The locale of the calendar cell. |
| Name | Description |
|---|---|
(default) | The content of the calendar cell. |
No custom events available.
| Part Name | Description |
|---|---|
base | The main calendar cell container. |
today-mark | The today mark of the calendar cell. |
| Property Name | Description |
|---|---|
--dds-calendar-cell-display | The display property of the calendar cell host (default: flex) |
--dds-calendar-cell-position | The position property of the calendar cell host (default: relative) |
--dds-calendar-cell-border-radius | The border radius of the calendar cell (default: var(--dds-radius-rounded)) |
--dds-calendar-cell-min-width | The minimum width of the calendar cell (default: var(--dds-spacing-1000)) |
--dds-calendar-cell-height | The height of the calendar cell (default: var(--dds-spacing-1000)) |
--dds-calendar-cell-min-height | The minimum height of the calendar cell (default: var(--dds-spacing-1000)) |
--dds-calendar-cell-color | The text color of the calendar cell (default: var(--dds-button-subtle-text-neutral-enabled)) |
--dds-calendar-cell-font-size | The font size of the calendar cell (default: var(--dds-font-sm)) |
--dds-calendar-cell-font-weight | The font weight of the calendar cell (default: var(--dds-font-weight-medium)) |
--dds-calendar-cell-text-align | The text alignment of the calendar cell (default: center) |
--dds-calendar-cell-cursor | The cursor style of the calendar cell (default: pointer) |
--dds-calendar-cell-background-hover | The background color of the calendar cell on hover (default: var(--dds-background-neutral-medium)) |
--dds-calendar-cell-background-active | The background color of the calendar cell when active (default: var(--dds-background-neutral-strong)) |
--dds-calendar-cell-selected-background | The background color of the selected calendar cell (default: var(--dds-button-primary-background-enabled)) |
--dds-calendar-cell-selected-color | The text color of the selected calendar cell (default: var(--dds-button-primary-text-enabled)) |
--dds-calendar-cell-selected-background-hover | The background color of the selected calendar cell on hover (default: var(--dds-button-primary-background-hover)) |
--dds-calendar-cell-selected-background-pressed | The background color of the selected calendar cell when pressed (default: var(--dds-button-primary-background-pressed)) |
--dds-calendar-cell-selected-today-mark-background | The background color of the today mark in selected calendar cell (default: var(--dds-text-neutral-on-inverted)) |
--dds-calendar-cell-disabled-color | The text color of the disabled calendar cell (default: var(--dds-text-neutral-disabled)) |
--dds-calendar-cell-disabled-cursor | The cursor style of the disabled calendar cell (default: not-allowed) |
--dds-calendar-cell-out-of-range-color | The text color of the out-of-range calendar cell (default: var(--dds-text-neutral-placeholder)) |
--dds-calendar-cell-today-font-weight | The font weight of the today calendar cell (default: var(--dds-font-weight-bold)) |
--dds-calendar-cell-header-background | The background color of the header calendar cell (default: transparent) |
--dds-calendar-cell-header-color | The text color of the header calendar cell (default: var(--dds-text-neutral-base)) |
--dds-calendar-cell-header-text-transform | The text transform of the header calendar cell (default: capitalize) |
--dds-calendar-cell-header-cursor | The cursor style of the header calendar cell (default: default) |
--dds-calendar-cell-in-range-color | The text color of the in-range calendar cell (default: var(--dds-button-primary-text-enabled)) |
--dds-calendar-cell-in-range-background-hover | The background color of the in-range calendar cell on hover (default: var(--dds-button-primary-background-hover)) |
--dds-calendar-cell-in-range-background-pressed | The background color of the in-range calendar cell when pressed (default: var(--dds-button-primary-background-pressed)) |
--dds-calendar-cell-range-background | The background color of the range start/end calendar cell (default: var(--dds-button-primary-background-enabled)) |
--dds-calendar-cell-range-color | The text color of the range start/end calendar cell (default: var(--dds-button-primary-text-enabled)) |
--dds-calendar-cell-range-today-mark-background | The background color of the today mark in range start/end calendar cell (default: var(--dds-text-neutral-on-inverted)) |
--dds-calendar-cell-today-mark-bottom | The bottom position of the today mark (default: var(--dds-spacing-100)) |
--dds-calendar-cell-today-mark-width | The width of the today mark (default: 5px) |
--dds-calendar-cell-today-mark-height | The height of the today mark (default: 5px) |
--dds-calendar-cell-today-mark-stroke | The stroke color of the today mark (default: var(--dds-border-neutral-transparent)) |
--dds-calendar-cell-today-mark-background | The background color of the today mark (default: var(--dds-background-neutral-medium-inverted)) |
--dds-calendar-cell-today-mark-fill | The fill color of the today mark (default: var(--dds-background-neutral-medium-inverted)) |