Skip to content

Repeat Days

Build a weekday picker for a repeating schedule, with round day buttons. Each sv-toggle has a value and an aria-label with the full day name, and the group's valuechange event updates the summary.

Since value follows the order of the buttons, the summary lists the days from Monday on, whatever order they were pressed in.

Repeat on M T W T F S S

Repeats every Monday, Wednesday, and Friday

Code

The following example assumes that you have imported the components and set up the theme.

Repeat Days
<div class="repeat-days">
13 collapsed lines
<span id="repeat-label">Repeat on</span>
<sv-toggle-group class="days" aria-labelledby="repeat-label" value="mon wed fri">
<sv-toggle aria-label="Monday" title="Monday" value="mon">M</sv-toggle>
<sv-toggle aria-label="Tuesday" title="Tuesday" value="tue">T</sv-toggle>
<sv-toggle aria-label="Wednesday" title="Wednesday" value="wed">W</sv-toggle>
<sv-toggle aria-label="Thursday" title="Thursday" value="thu">T</sv-toggle>
<sv-toggle aria-label="Friday" title="Friday" value="fri">F</sv-toggle>
<sv-toggle aria-label="Saturday" title="Saturday" value="sat">S</sv-toggle>
<sv-toggle aria-label="Sunday" title="Sunday" value="sun">S</sv-toggle>
</sv-toggle-group>
<p class="summary" aria-live="polite">Repeats every Monday, Wednesday, and Friday</p>
</div>
<script type="application/x-typescript" module>
20 collapsed lines
const DAY_NAMES = {
mon: "Monday",
tue: "Tuesday",
wed: "Wednesday",
thu: "Thursday",
fri: "Friday",
sat: "Saturday",
sun: "Sunday",
};
const listFormat = new Intl.ListFormat("en", { style: "long", type: "conjunction" });
const days = document.querySelector<ToggleGroup>(".days")!;
const summary = document.querySelector(".summary")!;
days.addEventListener("valuechange", () => {
const names = days.value.map(day => DAY_NAMES[day as keyof typeof DAY_NAMES]);
summary.textContent =
names.length > 0 ? `Repeats every ${listFormat.format(names)}` : "Does not repeat";
});
</script>
<style>
29 collapsed lines
.repeat-days {
display: grid;
gap: 0.75em;
justify-items: center;
> span {
font-weight: 600;
}
}
.days {
flex-wrap: wrap;
gap: 0.4em;
justify-content: center;
sv-toggle {
inline-size: 2.2em;
block-size: 2.2em;
padding: 0;
border-radius: 50%;
}
}
.summary {
margin: 0;
font-size: 0.85em;
color: var(--sv-gray-3);
text-align: center;
}
</style>