---
title: 'Calendar: Use Cases'
parts:
- Calendar
- Use Cases
eleventyNavigation:
key: 'Calendar: Use Cases'
order: 0
parent: Calendar
title: Use Cases
---
# Calendar: Use Cases
```js script
import { html, css } from '@mdjs/mdjs-preview';
import '@lion/ui/define/lion-calendar.js';
```
## Selected date
The `selectedDate` is the date which is currently marked as selected.
You usually select a date by clicking on it with the mouse or hitting Enter on the keyboard.
The `selectedDate` might not be within the dates in the current month view.
```js preview-story
export const selectedDate = () => html`
`;
```
## Central Date
The `centralDate` defines which day will be focused when keyboard moves the focus to the current month grid.
By default it is set to today, or the enabled day of the current month view that is closest to today's date.
The next and previous months' buttons work by changing the `centralDate` with plus or minus one month.
Changing the `centralDate` may mean a different view will be displayed to your users if it is in a different month.
Usually if you change only the day, "nothing" happens as it's already currently in view.
The `centralDate` can be different from `selectedDate` as you can have today as actively selected but still look at date that is years ago.
When the `selectedDate` changes, it will sync its value to the `centralDate`.
```js preview-story
export const centralDate = () => {
const today = new Date();
const centralDate = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate());
return html`
`;
};
```
## Controlling focus
You can control the focus by calling the following methods
- `focusCentralDate()`
- `focusSelectedDate()`
- `focusDate(dateInstanceToFocus)`
> Be aware that the central date changes when a new date is focused.
```js preview-story
export const controllingFocus = () => {
const today = new Date();
const selectedDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 1);
const centralDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 5);
return html`
`;
};
```
## Limiting selectable values
### Providing a lower limit
To give a lower limit you can bind a date to the `minDate` property.
```js preview-story
export const providingLowerLimit = () => {
const minDate = new Date();
return html`
`;
};
```
### Provide a higher limit
To give a higher limit you can bind a date to the `maxDate` property. In this example, we show how to create an offset of + 2 days.
```js preview-story
export const providingHigherLimit = () => {
const today = new Date();
const maxDate = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 2);
return html`
`;
};
```
### Provide a list of disabled dates
In some cases a specific date or day of the week needs to be disabled, supply those days to the `disableDates` property.
```js preview-story
export const disabledDates = () => html`
`;
```
### Combined disable dates
To limit the scope of possible dates further, combine the methods mentioned above.
```js preview-story
export const combinedDisabledDates = () => {
const today = new Date();
const maxDate = new Date(today.getFullYear(), today.getMonth() + 2, today.getDate());
return html`
`;
};
```
### Finding enabled dates
The next available date may be multiple days/month in the future/past.
For that we offer convenient helpers as
- `findNextEnabledDate()`
- `findPreviousEnabledDate()`
- `findNearestEnabledDate()`
```js preview-story
export const findingEnabledDates = () => {
function getCalendar(ev) {
return ev.target.parentElement.querySelector('.js-calendar');
}
return html`
`;
};
```