Question presented to candidate: "Build a date picker for our booking form, without a date library. A button shows the chosen date; clicking it opens a calendar for one month. The user can move between months and years, pick a day, and do all of it from the keyboard. Dates before a minimum must not be selectable, and today should stand out."
Requirements:
- A trigger button that opens a popup calendar and shows the selected date in words.
- A month grid with weekday headers, always 6 rows of 7 days, including leading and trailing days of the neighbouring months.
- Previous and next month and year buttons, disabled when the whole target month is out of range.
- Today highlighted, the selected day marked, days outside
min/maxdisabled. - Keyboard: arrows move by day and week, Home / End to the week edges, PageUp / PageDown by month, Shift+PageUp / PageDown by year, Enter or Space to select, Escape to close.
- Focus moves into the grid on open and returns to the trigger on close; clicking outside closes the popup.
What a strong answer should cover:
- Representing a calendar date without a time zone (an ISO
YYYY-MM-DDstring or a year/month/day triple), and doing day arithmetic throughDate.UTCor the month-overflow trick, never by adding86400000ms to a local midnight. - Grid generation: leading blanks from the weekday of the 1st, month lengths and leap years from
new Date(y, m + 1, 0), a fixed 42-cell grid. - Keyboard grid navigation with a roving
tabindex, and moving DOM focus after the re-render. - The WAI-ARIA date picker dialog pattern:
role="dialog",role="grid",aria-selected,aria-current="date", a live month heading, a focus trap and focus return. - Clamping: month jumps from the 31st land on the last day of a shorter month, and focus never leaves
min/max.
Clarifying questions expected:
- "Which day does the week start on, and do we need locales other than English?"
- "Should picking a day close the popup, or is there an OK button?"
- "Can the user type a date as well, or only pick one?"
Code / implementation expected: Yes. A working component with the date helpers, the grid, keyboard handling and focus management.