Web component implementation of a Spectrum Calendar
npm install @spectrum-web-components/calendar elements display all the days within a given month, indicating the current day. Users can also see past or future months, and select a specific date via pointer, Space or Enter.


```
yarn add @spectrum-web-components/calendar
Import the side effectful registration of via:
``
import '@spectrum-web-components/calendar/sp-calendar.js';
When looking to leverage the Calendar base class as a type and/or for extension purposes, do so via:
``
import { Calendar } from '@spectrum-web-components/calendar';
By default, the element will display the current month with emphasis on the current day and no pre-selected date.
`html`
A pre-selected date value can be provided to the element and it will dictate the displayed month of the element.value
Setting the property requires a DateValue type (DateValue = CalendarDate | CalendarDateTime | ZonedDateTime).element.value
When reading the value by , the consumer will always receive a CalendarDate type value.@internationalized/date
More about these types and when to use each one can be found on the page.
To clear the element's value, the clear method can be used. (element.clear())
`ts
import {CalendarDate} from '@internationalized/date';
>
`
The min and max properties can be used to limit the selected value to a specific range. Ranges can be open, by providing only one of the mentioned properties, or closed, when both min and max are provided. These properties are also of DateValue type, but will always be of CalendarDate type when read, similar to value.
If the provided closed interval is not a valid one (e.g min > max), the assignment of those properties gets ignored. The same way, if a pre-selected value doesn't comply with the interval, it gets ignored and the element will behave as it wouldn't have a value provided.
`html-live
`
In order to react to date selection changes, consumers can leverage the change event and read the value of the event target in the handler.
`ts
import { CalendarDate } from '@internationalized/date';
import { Calendar } from '@spectrum-web-components/calendar';
const handleCalendarChange = (event: Event) => {
const selectedDate = (event.target as Calendar).value as CalendarDate;
// use the selectedDate...
};
`
The element supports multiple locales and updates its content accordingly.element.locale represents the language in which the element is currently being delivered. By default, the value will represent the language established by the lang attribute on the root element, with a fallback to navigator.language. This can be customized via a language context provider by a parent element that listens for sp-language-context event and supplies update language settings to the callback function. Applications leveraging the element to manage the visual delivery or text direction of their content will also be provided with a reactive context for supplying language information to its descendants.
Currently the elements supports only the Gregorian calendar and the AD era.
While providing support for screen readers, the element needs some labels to be internationalized by the consumer to offer non-english alternatives. This can be done via the labels` property.