A theme select is a headless component that allows users to switch between different visual themes or color schemes using a native <select> dropdown. It is commonly used to offer light, dark, high-contrast, or other visual modes, enhancing personalization and accessibility by letting users adapt the interface to their preferences or environment.
The consumer provides <option> elements as children to define the available themes. The component uses aria-label for accessible naming and supports two-way binding on the selected theme.
<script lang="ts">
import ThemeSelect from "./ThemeSelect.svelte";
import ThemeSelectOption from "../ThemeSelectOption/ThemeSelectOption.svelte";
let theme = $state("light");
</script>
<ThemeSelect label="Theme" bind:value={theme}>
<ThemeSelectOption value="light">Light</ThemeSelectOption>
<ThemeSelectOption value="dark">Dark</ThemeSelectOption>
<ThemeSelectOption value="system">System Default</ThemeSelectOption>
</ThemeSelect>
Show Svelte source
// In your Svelte component:
import ThemeSelect from "lily-design-system-svelte-headless/components/ThemeSelect/ThemeSelect.svelte";
<ThemeSelect>
<!-- content -->
</ThemeSelect>
Use ThemeSelect when you need a dropdown for switching visual themes. Common scenarios include light/dark mode toggles, high-contrast themes for accessibility, or branded theme options. Pair with ThemeSelectOption for individual options, or use plain <option> elements.
This headless component provides a native <select> element with an aria-label for accessible theme switching. Keyboard navigation and dropdown behavior come from the browser's native select. The consumer provides <option> children (or ThemeSelectOption components) and all visual styling.
Styles
The consumer provides all CSS styling. The component renders with a .theme-select class for targeting. No default styles are included — this is a fully headless component.
Testing
Verify the component renders a <select> element with class theme-select
Verify aria-label={label} -- provides an accessible name for the theme select since there is no visible <label>` element
Verify keyboard interactions work correctly
Verify pass-through attributes are applied
Advice
Designers: Ensure the selected option clearly indicates the active theme. Consider showing a preview swatch next to each option label.
Developers: Apply the selected theme value to the document root (e.g., data-theme attribute or CSS class) and persist the choice across sessions.
Implementation Notes
Renders a <select> element with class theme-select
Spreads restProps onto the root element for consumer customization
Composition
ThemeSelect contains ThemeSelectOption children (or plain <option> elements) following the Select/SelectOption pattern. ThemeSelect is also related to ThemeSelect (radio-based approach) and ThemeView (read-only display).
Related components
theme-select-option — one option in a theme select dropdown