Skip to content
Likable Aurora @likable-hair/svelte 5

MonthSelector

Grid of the twelve months, to choose one. Names come from locale through Intl. Without aria-label or aria-labelledby it is named "Month", in the language of locale. year tells which month is the current one (it has a border) and, with min and max, which months cannot be chosen. It is an ARIA listbox: one Tab stop, the arrows move in the grid, Home and End go to the first and last month, Enter or Space choose. Its state is exposed as data-disabled on the grid and as data-selected, data-current and data-disabled on the months, for app CSS.

import { MonthSelector } from '@likable-hair/svelte';

src/lib/components/simple/dates/MonthSelector.svelte · Markdown for LLMs

Choose a month

The twelve months of year. The current month has a border; with min and max the months outside them cannot be chosen.

Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
Code
<script lang="ts">
	import { MonthSelector } from '@likable-hair/svelte';

	let selectedMonth = $state<number | undefined>(8);
</script>

<div class="example">
	<MonthSelector
		bind:selectedMonth
		year={2026}
		max={new Date(2026, 10, 30)}
		aria-label="Billing month"
	/>
</div>

<style>
	.example {
		width: 270px;
	}
</style>

Props

NameTypeDefaultDescription
selectedMonth bindable numberChosen month, from 0 (January) to 11.
year numberYear of the months: it decides the current month and, with min and max, which months are disabled. Defaults to the current year.
locale stringBCP 47 locale of the month names and of the default accessible name. Defaults to the one set with setDefaultLocale, else en.
monthFormat 'short' | 'long''short'Length of the month names. Screen readers always read the full name.
min DateMonths that end before this day cannot be chosen.
max DateMonths that start after this day cannot be chosen.
disabled booleanfalseShows the months without letting anyone choose them.
class { container?: string; month?: string }{}Extra classes for each part.
monthSelectorElement bindable HTMLDivElementThe grid element.

It also accepts the native attributes and events of <div> (for example id, title, aria-label, onkeydown), which are forwarded to the element.

Snippets

NameParametersDescription
itemSnippet{ month: number; label: string; name: string; selected: boolean; current: boolean; disabled: boolean; }Replaces the name of a month. The cell around it keeps click, keyboard and state.

Events

NameTypeDescription
onchange(event: { month: number }) => voidCalled when the user chooses a month.

Methods

Call them on the instance: <MonthSelector bind:this={ref} />, then ref.focus().

SignatureDescription
focus()Moves the focus into the grid: to the last focused month, else the chosen one or the current one.

CSS variables

For a single instance, pass them as style props: <MonthSelector --month-selector-background="tomato">. The --month-selector-default-* defaults apply to the whole app: override them in :root or in a theme.

Per-instance variableDefault
--month-selector-columns
--month-selector-default-columns 3
--month-selector-gap
--month-selector-default-gap 6px
--month-selector-width
--month-selector-default-width 100%
--month-selector-height
--month-selector-default-height auto
--month-selector-padding
--month-selector-default-padding 8px 0
--month-selector-border-radius
--month-selector-default-border-radius var(--global-radius-sm)
--month-selector-background
--month-selector-default-background transparent
--month-selector-color
--month-selector-default-color var(--global-color-text-2)
--month-selector-font-size
--month-selector-default-font-size 14px
--month-selector-font-weight
--month-selector-default-font-weight 500
--month-selector-current-border-color
--month-selector-default-current-border-color var(--global-color-border-strong)
--month-selector-hover-background
--month-selector-default-hover-background var(--global-color-surface-2)
--month-selector-hover-color
--month-selector-default-hover-color var(--global-color-text)
--month-selector-focus-ring-color
--month-selector-default-focus-ring-color var(--global-focus-ring-color)
--month-selector-selected-background
--month-selector-default-selected-background var(--global-fill-primary)
--month-selector-selected-color
--month-selector-default-selected-color var(--global-color-on-primary)
--month-selector-selected-box-shadow
--month-selector-default-selected-box-shadow var(--global-shadow-fill)
--month-selector-disabled-opacity
--month-selector-default-disabled-opacity 0.35