Month and year navigation with one availability rule
Navigate two months with compact month and year choices. The same unavailable dates and weekday policy validate calendar picks, typed dates and explicit date ranges.
Keyboard
- Month and Year choices support arrow navigation and typeahead. Day buttons retain calendar arrow, Home, End and Page keys.
- Type an unavailable date or a range crossing one: submission keeps the draft and focuses the invalid text.
States covered
- Two-month display
- Controlled month
- Custom month and year choices
- Exact unavailable dates
- Weekday policy
- Shared typed validation
- Responsive month and year groups
- English and Arabic navigation
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-calendar-navigation-availability.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import {useState} from 'react';
import {Button,Calendar,DatePicker,DateRangePicker,formatDateValue,parseDateValue,UIProvider} from '@bld8/ui';
const date=(value:string)=>parseDateValue(value)!;
const unavailable=[date('2026-11-17')],weekend=(value:Date)=>value.getDay()===0||value.getDay()===6;
export default function CalendarAvailabilityExample(){const [month,setMonth]=useState(date('2026-11-01')),[selected,setSelected]=useState<Date|undefined>(date('2026-11-16')),[status,setStatus]=useState('No available date submitted.'),[arabic,setArabic]=useState(false);return <UIProvider locale={arabic?'ar':'en-AU'} direction={arabic?'rtl':'ltr'}><div style={{display:'grid',gap:24,maxWidth:720}}>
<Button variant="secondary" onClick={()=>setArabic(value=>!value)}>{arabic?'Use English calendar':'Use Arabic calendar'}</Button>
<Calendar label="Review calendar" navigation="dropdowns" month={month} onMonthChange={setMonth} numberOfMonths={2} value={selected} onValueChange={setSelected} startMonth={date('2025-01-01')} endMonth={date('2027-12-01')} minDate={date('2026-11-01')} maxDate={date('2027-05-31')} unavailableDates={unavailable} isDateUnavailable={weekend}/>
<p data-calendar-selection>{'Selected: '+formatDateValue(selected)}</p>
<form aria-label="Available date form" style={{display:'grid',gap:20}} onSubmit={event=>{event.preventDefault();const data=new FormData(event.currentTarget);setStatus('Date: '+data.get('available')+' | Range: '+data.get('period.from')+' to '+data.get('period.to'));}}>
<DatePicker label="Available review date" editable name="available" defaultValue={date('2026-11-16')} minDate={date('2026-11-01')} maxDate={date('2027-05-31')} unavailableDates={unavailable} isDateUnavailable={weekend} navigation="dropdowns"/>
<DateRangePicker label="Available period" editable name="period" commitMode="explicit" defaultValue={{from:date('2026-11-02'),to:date('2026-11-04')}} minDate={date('2026-11-01')} maxDate={date('2027-05-31')} unavailableDates={unavailable} isDateUnavailable={weekend} navigation="dropdowns" numberOfMonths={2}/>
<Button type="submit">Read available dates</Button>
</form><p role="status">{status}</p>
</div></UIProvider>;}