Skip to the content
Konstruktor UI

Website pieces

Theme picker

<kui-theme-picker> lets a person choose the product’s colour among its allowed themes, and with modes also light, dark or as the device. The choice is kept in this browser and applies to the whole page at once.

<kui-theme-picker> needs kui.js; the markup works without it as described below

Examples

Themes and modes

This picker changes this reference site, like the one in its top bar. The themes come from the themes attribute, else from the page’s kui-themes meta tag.

HTML
<kui-theme-picker themes="gold ocean teal forest plum rose coral slate sand ink" modes></kui-theme-picker>

Modes only

A product with one colour shows only the mode. With a single theme no swatches are drawn.

HTML
<kui-theme-picker themes="gold" modes></kui-theme-picker>

In a popover in the header

The usual place: an icon button in the top bar that opens the picker.

HTML
<kui-popover placement="bottom-end">
  <button class="kui-button kui-button--icon kui-button--ghost" type="button" aria-label="Colour and appearance"><svg class="kui-icon" aria-hidden="true"><use href="kit/icons.svg#palette"></use></svg></button>
  <div class="kui-popover" role="dialog" aria-label="Colour and appearance" hidden>
    <kui-theme-picker themes="gold ocean plum" modes></kui-theme-picker>
  </div>
</kui-popover>

Classes and attributes

<kui-theme-picker themes="…">
The allowed themes, separated by spaces. Without it, the page’s meta name="kui-themes".
modes
Adds the light, dark and device choice.
<meta name="kui-themes" content="…">
The themes a product allows. kui.setTheme refuses any other.
kui.setTheme(name), kui.setMode(mode)
The same change from script. mode is light, dark or system.
kui-theme-change
The event on document after every change, with detail.theme and detail.mode.

Keyboard

Tab
Moves to the chosen swatch, then to the chosen mode.
Arrow keys
Choose another theme or mode within its group.

Accessibility

  • Both groups are native radio buttons in a fieldset with a legend, so they are read as “Theme, 1 of 10” and “Mode”.
  • Each swatch has the theme’s name as its accessible name and as a tooltip title.
  • Every theme keeps the kit’s contrast ratios in both modes; the theme check fails otherwise.

Do and do not

Do

  • Offer the device mode as well as light and dark.
  • Let each product limit its themes to the ones that suit it.

Do not

  • Do not ask for a theme on the first visit.
  • Do not let one product’s picker offer a theme its brand does not use.