vael-ui v0.5.7

Forms & inputs

Layout

Calendar

A month grid for picking a single date or a date range. Use it when the calendar should stay on the page.

Install

import { Calendar } from 'vael-ui'

Playground

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ref } from 'vue'
import { Calendar } from 'vael-ui'
import type { CalendarRange } from 'vael-ui'

const value = ref<Date | CalendarRange | null>(null)
</script>

<template>
  <Calendar locale="en-US" v-model="value" />
</template>

Props

NameTypeDefaultDescription
selectionMode'single' | 'range''single''range' picks a start then an end; clicking before the start restarts the range.
view'date' | 'month' | 'year''date'What a click selects: a day, a month (its 1st) or a year (January 1st).
minDateDateEarliest selectable date (inclusive); the calendar disables earlier days, months and years.
maxDateDateLatest selectable date (inclusive); the calendar disables later days, months and years.
disabledDatesCalendarDisabledDatesList of unavailable dates, or a predicate function. Matching compares calendar days and ignores time.
localestringBCP-47 locale for month and weekday names and the week start day. Unset, it uses the runtime default.
firstDayOfWeeknumber0 (Sunday) to 6 (Saturday). Unset, it derives from locale and falls back to Monday.
monthsnumber1How many months to show side by side, for picking a range at a glance. They move together and wrap onto separate rows when there isn't room.
showYearButtonsbooleanfalseAdds « and » beside the month arrows to jump a year at a time, handy for ranges that span years. Only in the day view; the month and year grids already step by years.
showWeekNumbersbooleanfalseShows each week's number (ISO 8601) at the start of its row.
plannerbooleanfalseLays the month out as a planner: the calendar fills its container, the seven columns share the width, and each day is a box that grows with what you put in #day (tasks, events, a Sortable to drag them between days), with the date at its top start. A click on a control inside a day is that control's, not a selection.
motionCalendarMotiontruefalse skips the month change's slide. An object restyles it: give the label and grid looks as values, or as functions of where.direction (1 forward, -1 back).
uiPartial<Record<'root' | 'header' | 'navButton' | 'label' | 'weekdays' | 'weekday' | 'grid' | 'cell', UiPartValue>>Class and style overrides for each part.
modelValueDate | CalendarRange | nullnullSelected date, or { start, end } in range mode.

Events

NameTypeDescription
update:modelValue(value: Date | CalendarRange | null)Fires when modelValue changes (v-model).
change(value: Date | CalendarRange | null)Fires when you pick a date, month, year or range endpoint.
month-change(value: Date)Fires when the displayed month changes (nav buttons, keyboard, or clicking an adjacent month's day).

Slots

NameTypeDescription
label{ label: string; date: Date; level: CalendarView; }Custom content for the month and year heading (defaults to its text). The heading keeps its own click-to-pick-month/year, keyboard and aria wiring. With months, each month's label.
day{ date: Date; isCurrentMonth: boolean; isToday: boolean; isSelected: boolean; isDisabled: boolean; }Custom content inside each day cell (defaults to the day number). The cell keeps its own click, keyboard and aria wiring.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
rootElHTMLElement | nullRoot element (same as el).
gridElHTMLElement | nullDay grid element (null while the month or year grid shows).
highlightElHTMLElement | nullThe hover and keyboard highlight, sliding between cells. With motion: false it moves at once, for your own animation.
goToPreviousMonth() => voidSteps back one page: a month, or a year or 12 years in the month and year grids.
goToNextMonth() => voidSteps forward one page: a month, or a year or 12 years in the month and year grids.
focusDay(day: Date) => voidMoves keyboard focus to the given day, switching months if needed. With view set to 'month' or 'year', focuses its month or year.

Motion New

How Calendar's label and grid change months. Give each part's look as values, or as a function of where: its direction is 1 going forward and -1 going back.

<Calendar
  :motion="{ initial: { label: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitlabelgridSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

Follows the Grid pattern from the WAI-ARIA Authoring Practices Guide.

KeyAction
ArrowLeftArrowRightMoves focus one day back or forward.
ArrowUpArrowDownMoves focus one week back or forward.
HomeEndMoves focus to the first or last day of the week.
PageUpPageDownMoves focus one month back or forward.
ShiftPageUpShiftPageDownMoves focus one year back or forward.
EnterSpaceSelects the focused day.
ArrowLeftArrowRightArrowUpArrowDownMoves focus one cell or one row in the month and year views.
HomeEndMoves focus to the first or last cell in the row, in the month and year views.
PageUpPageDownMoves focus a year back or forward in the month view, or 12 years in the year view.
EnterSpacePicks the focused month or year, and moves focus into the next view.
  • Each month is a role="grid" named by its month and year. Days are gridcells with the full date as aria-label, plus aria-selected, aria-current="date" for today and aria-disabled. With showWeekNumbers, each row starts with a rowheader, such as “Week 12”.
  • One cell is in the tab order at a time (roving tabindex). Moving past the shown month pages the calendar. In a range, every day from the start to the end has aria-selected.
  • The previous and next buttons use aria-disabled at minDate and maxDate, so they keep focus. The month label is an aria-live="polite" button, so paging announces the new month.
  • With a #day slot, the full date is read from visually hidden text before your content. Right to left, ArrowLeft and ArrowRight swap.