Layout
Appearance
Light and dark mode: the script that applies the user's choice before the page paints, and the controls that change it. tk:html already includes tk:appearance, so most apps only place one of the controls: a toggle button, a three-way selector, or the account menu that carries one of them.
tk:appearance.menu renders its own tk:appearance.menu-item; the tag is only written to put the theme row in a menu built by hand.
Nothing to show
A button with a sun in light mode and a moon in dark mode. Clicking it switches to the other mode, with the new colors spreading in a circle from the button, and the choice is remembered in the browser.
Choosing between system, light and dark #
Three icon buttons in a group: System, Light and Dark, with the current one highlighted. System follows the operating system and keeps following it when it changes.
Nothing to show
Account menu with the theme inside #
An avatar that opens a menu. The first row is "Theme", with the selector at its end, followed by a separator and the items. Picking a theme does not close the menu. With no items and no slot content there is no menu, and the tag renders the toggle button alone.
Nothing to show
A control of your own #
$tallkit.appearance (or $tk.appearance) is what the controls use. apply() takes system, light or dark; mode is reactive and holds the current choice; isDark() and isLight() tell what is on screen, which in system mode depends on the operating system.
Nothing to show
Without tk:html #
In a layout that does not use tk:html, put the tag in the <head>, before the stylesheets. It prints a small inline script that adds the dark class to <html> before the first paint, so a dark page never flashes light.
Nothing to show
Toggle options #
The toggle takes the element props, such as label and kbd, and the tk:button attributes. animate set to false switches instantly; an array sets the reveal options.
Nothing to show
Menu controls #
control set to toggle puts the toggle button beside the menu instead of the row inside it, and false leaves the theme out. With no items, the tag renders the toggle alone.
Nothing to show
Theme row in your own menu #
tk:appearance.menu-item is the theme row on its own, for a menu built by hand. label and icon change its text and icon.
Nothing to show
Survives Livewire updates #
The mode lives in the browser, so a Livewire request leaves it alone. Switch the theme, then save: the selector keeps its state.
Nothing to show
Customization #
Attributes go to the button group; system:, light: and dark: reach each button, here to change the tooltips.
Nothing to show
Reference
tk:appearance
tk:appearance.toggle
tk:appearance.selector
tk:appearance.menu
└── tk:appearance.menu-item
tk:appearance.view
tk:appearance
| Prop | Type | Default | Description |
|---|---|---|---|
nonce |
string | none | The CSP nonce set on the inline <style> and <script>. |
In tk:html the tag is controlled by the appearance prop: true (default) includes it with the page nonce, a string is used as the nonce, and false leaves it out.
Prefixes
| Prefix | Goes to |
|---|---|
style: |
The inline <style> element. |
script: |
The inline <script> element. |
tk:appearance.toggle
| Prop | Type | Default | Description |
|---|---|---|---|
animate |
bool | array | true |
The circular reveal when switching. false switches instantly; an array is passed as the animation options, e.g. ['duration' => 600], over the defaults of 300 ms and ease-in. |
Also accepts the element props (label, suffix, kbd...), and every other attribute goes to the tk:button it renders, with variant="subtle" and the tooltip "Toggle light and dark mode" as defaults.
Slots
| Slot | Description |
|---|---|
| default | Content of the button, between the two icons, in place of label. |
tk:appearance.selector
Has no props of its own. Attributes go to the tk:button.group it renders, so its props (size, for instance) apply.
Prefixes
| Prefix | Goes to |
|---|---|
system: |
The System button. |
light: |
The Light button. |
dark: |
The Dark button. |
tk:appearance.menu
| Prop | Type | Default | Description |
|---|---|---|---|
control |
bool | string | automatic | Which theme control to render. By default the selector row inside the menu, or the toggle button when there is no menu. toggle renders the toggle button beside the menu and no row inside it; selector renders only the row; false renders no theme control. |
items |
array | none | The menu items, as in tk:menu. |
Every other attribute goes to the tk:avatar.menu it renders (name, src, profile, size...). Without items or a slot there is no menu, and they go to the toggle button instead (<tk:appearance.menu class="ms-auto" />).
Slots
| Slot | Description |
|---|---|
| default | Menu items written by hand. |
Prefixes
| Prefix | Goes to |
|---|---|
toggle: |
The toggle button. |
menu-item: |
The theme row inside the menu. |
tk:appearance.menu-item
| Prop | Type | Default | Description |
|---|---|---|---|
label |
string | slot | Theme |
The text of the row, translated. |
icon |
string | slot | mdi:palette-outline |
The icon before the label. |
Also accepts the other element props.
Prefixes
| Prefix | Goes to |
|---|---|
selector: |
The selector at the end of the row. |
tk:appearance.view
| Prop | Type | Default | Description |
|---|---|---|---|
livewire |
string | none | The name of a Livewire component to mount in each half, after the slot. |
Slots
| Slot | Description |
|---|---|
| default | The content to preview, rendered once in each half. |
Customization
Classes and attributes on a tag go to its root element, except on tk:appearance, which only takes prefixed attributes. To reach an inner element, prefix the attribute (listed in the Reference above).
tk:appearance.menu also takes the prefixes of tk:avatar.menu (trigger:, menu:, avatar:...).
Nothing to show
Accessibility
The selector follows the WAI-ARIA radio group pattern: the group has role="radiogroup" with the label "Theme", each button role="radio" with aria-checked, and only the checked one is in the tab order. The buttons have no text, so each takes its accessible name from its tooltip. The toggle is a plain button named by its tooltip, "Toggle light and dark mode", unless it has a label.
| Key | Action |
|---|---|
| Arrow Right / Arrow Down | Selector: applies the next mode and moves focus to it, wrapping from Dark to System. |
| Arrow Left / Arrow Up | Selector: applies the previous mode and moves focus to it, wrapping from System to Dark. |
| Tab | Moves into the selector, to the checked button, and out of it. |
| Enter, Space | Toggle: switches between light and dark. |
Arrow Left and Arrow Right are swapped in a right-to-left page. In the menu opened with the keyboard, focus lands on the "Theme" row and Tab moves from it into the selector.
Behavior notes
- The choice is kept in
localStorage, undertallkit.appearance, aslightordark. Choosing System removes the key, and a browser with nothing stored follows the operating system. - Dark mode is the
darkclass on<html>, which also getscolor-scheme: dark, so native scrollbars and form controls follow. - The toggle only knows light and dark. Used while in
systemmode, it switches to the opposite of what is on screen and stores that, so the page stops following the system until System is picked in a selector orapply('system')is called. - The reveal animation of the toggle uses the View Transitions API. Where the browser does not support it, or the user asked for reduced motion, the switch is instant.
- All controls on the page reflect the same state: changing the mode in one updates every selector, and a change made in another tab of the same site is applied to this one.
- The state lives in the browser and is untouched by Livewire updates; the server never knows the mode.
tk:appearance.menuwithcontrol="selector"and noitemsor slot content renders nothing.tk:appearance.viewis a full page of its own (it renderstk:html, without the appearance script): two halves side by side, "Dark" and "Light", with the same content in each, for comparing a component in both modes.