DaySelect
DaySelect is a controlled row of buttons for selecting one or more days of the week.
Quick Start
- Installation
npm install @adaptavant/eds-core- Import
import { DaySelect } from '@adaptavant/eds-core';
Basic Usage
DaySelect is controlled: pass the selected values through value and update them in the onChange callback. Toggling a day adds or removes its value from the array.
const [value, setValue] = React.useState(['mon', 'thu', 'fri']);
return (
<Box className="flex flex-col gap-4 items-start">
<DaySelect onChange={setValue} value={value} />
<Text className="text-body-14 text-secondary">
Selected: {value.length ? value.join(', ') : 'none'}
</Text>
</Box>
);
Size
Use the size prop to switch between the two sizes. standard renders 3-letter labels in pill-shaped buttons; small renders 1-letter labels in compact circles.
const [value, setValue] = React.useState(['mon', 'thu', 'fri']);
return (
<Box className="flex flex-col gap-4 items-start">
<DaySelect onChange={setValue} size="standard" value={value} />
<DaySelect onChange={setValue} size="small" value={value} />
<Text className="text-body-14 text-secondary">
Selected: {value.length ? value.join(', ') : 'none'}
</Text>
</Box>
);
Localised labels
Set localeCode to render the default Monday-Sunday labels in another language. The values emitted through onChange stay stable ('mon'…'sun') regardless of locale — only the visible labels change.
To render those values elsewhere in your own UI, use getDayLabels(localeCode), which returns the same localized labels keyed by value.
const [value, setValue] = React.useState(['mon', 'wed', 'fri']);
const labels = getDayLabels('fr');
return (
<Box className="flex flex-col gap-4 items-start">
<DaySelect localeCode="fr" onChange={setValue} value={value} />
<Text className="text-body-14 text-secondary">
Selected:{' '}
{value.length
? value.map((day) => labels[day].fullLabel).join(', ')
: 'none'}
</Text>
</Box>
);
onChange always emits the selection in Monday-first order, so no sorting is needed.
Keyboard interactions
DaySelect is a single tab stop. Tab moves focus into the row and the next Tab moves out of it; within the row, focus is moved with the arrow keys.
| Key | Action |
|---|---|
Tab | Moves focus into the row, onto the last focused day, then out of the row |
ArrowRight | Moves focus to the next day, wrapping from Sunday to Monday |
ArrowLeft | Moves focus to the previous day, wrapping from Monday to Sunday |
Home | Moves focus to the first day |
End | Moves focus to the last day |
Enter or Space | Toggles the focused day |
Focus a day and use the arrow, Home and End keys to move between days.
API Reference
DaySelect
DaySelect Component
| Prop | Default | Description |
|---|---|---|
value | _ | DayValue[]The values of the currently selected days. DayValue is 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat' | 'sun'. |
onChange | _ | (value: DayValue[]) => voidCalled with the next selected values whenever a day is toggled. |
size? | 'standard' | 'standard' | 'small'The size of the day buttons. Standard shows 3-letter labels; small shows 1-letter labels. |
localeCode? | en | 'ar' | 'bg' | 'cs' | 'da' | 'de' | 'el' | 'en' | 'es' | 'et' | 'fi' | 'fr' | 'he' | 'hr' | 'hu' | 'is' | 'it' | 'ja' | 'ko' | 'lt' | 'lv' | 'nl' | 'no' | 'pl' | 'pt' | 'ro' | 'ru' | 'sl' | 'sq' | 'sr' | 'sv' | 'tr' | 'uk' | 'zh'Locale code (ISO 639-1) for date localization. |
aria-label? | 'Select days' | stringAccessible label for the group of day buttons. |
getDayLabels
Returns the localized day labels keyed by the values emitted through onChange, for rendering a selection elsewhere in your UI.
const labels = getDayLabels('fr');
// labels.mon.fullLabel === 'lundi'
Parameters
| Prop | Default | Description |
|---|---|---|
localeCode? | 'en' | LocaleCodeLocale code (ISO 639-1) for the returned labels. Accepts the same values as the localeCode prop. |
Return Value
Record<DayValue, ...> keyed by day value, where each entry has:
| Prop | Default | Description |
|---|---|---|
value | _ | DayValueThe day's stable value, e.g. 'mon'. |
label | _ | stringThe 3-letter form, e.g. 'Mon'. Rendered at the 'standard' size. |
shortLabel | _ | stringThe 1-letter form, e.g. 'M'. Rendered at the 'small' size. |
fullLabel | _ | stringThe full weekday name, e.g. 'Monday'. Used as each button's accessible label. |
Style API
Our design system components include style props that allow you to easily customize different parts of each component to match your design needs.
Please refer to the Style API documentation for more insights.
DaySelect parts
DaySelect exposes two style parts: root (the role="toolbar" row wrapping all the day buttons) and day (each individual day toggle button).
const [value, setValue] = React.useState(['mon', 'thu', 'fri']);
return (
<DaySelect
className="lg:gap-2 gap-3"
classNames={{
day: 'rounded-md',
}}
onChange={setValue}
value={value}
/>
);