Skip to content
Norn
Menu

norn-segmented-control

A row of mutually exclusive options drawn as one control, from native radio buttons in a fieldset. No script: the browser handles the keyboard and the form value. Each option is a <label> holding an <input type="radio">, an optional norn-icon with @size="m", and its text in a <span>. Give the radios one name, and the labels a title when the text is hidden. The checked option is tinted in the accent, and the others take a hover and a press layer. Options are drawn at equal widths. A component that builds one from its own props passes the legend slot, @name, and :@options instead, since its props don't reach slot content.

<norn-segmented-control> a component, from @allons-y/webc-patterns

Examples

Color scheme
Width

Open on its own

Source
<norn-segmented-control>
	<template slot="legend" webc:nokeep><span>View</span></template>
	<label><input type="radio" name="view" value="list" checked /><span>List</span></label>
	<label><input type="radio" name="view" value="grid" /><span>Grid</span></label>
	<label><input type="radio" name="view" value="table" /><span>Table</span></label>
</norn-segmented-control>
Color scheme
Width

Open on its own

Source
<norn-segmented-control @icon-only>
	<template slot="legend" webc:nokeep><span>Color scheme</span></template>
	<label title="Light"><input type="radio" name="scheme" value="light" /><norn-icon @name="sun" @size="m"></norn-icon><span>Light</span></label>
	<label title="System"><input type="radio" name="scheme" value="" checked /><norn-icon @name="system" @size="m"></norn-icon><span>System</span></label>
	<label title="Dark"><input type="radio" name="scheme" value="dark" /><norn-icon @name="moon" @size="m"></norn-icon><span>Dark</span></label>
</norn-segmented-control>
Color scheme
Width

Open on its own

Source
<norn-segmented-control
	webc:for="count of [3, 4, 5, 6, 7, 8]"
	:@name="'count-' + count"
	:@options="Array.from({ length: count }, (item, index) => ({ value: 'option-' + index, label: String(index + 1), checked: index === count - 1 }))"
>
	<span slot="legend" @text="count + ' options'"></span>
</norn-segmented-control>
Color scheme
Width

Open on its own

Source
<div style="display: grid; gap: 1.5rem">
	<div style="display: grid; gap: 0.5rem">
		<p><code>icon-only = true</code></p>
		<div>
			<norn-segmented-control @icon-only>
				<template slot="legend" webc:nokeep><span>View</span></template>
				<label><input type="radio" name="view" value="list" checked /><span>List</span></label>
				<label><input type="radio" name="view" value="grid" /><span>Grid</span></label>
				<label><input type="radio" name="view" value="table" /><span>Table</span></label>
			</norn-segmented-control>
		</div>
	</div>
	<div style="display: grid; gap: 0.5rem">
		<p><code>icon-only = false</code></p>
		<div>
			<norn-segmented-control>
				<template slot="legend" webc:nokeep><span>View</span></template>
				<label><input type="radio" name="view" value="list" checked /><span>List</span></label>
				<label><input type="radio" name="view" value="grid" /><span>Grid</span></label>
				<label><input type="radio" name="view" value="table" /><span>Table</span></label>
			</norn-segmented-control>
		</div>
	</div>
</div>

Props

Write them with the @ prefix, and :@ for an expression.

NameTypeDescription
@icon-only boolean Hides the option text visually; it stays the radio's name.
@name string The radios' shared name. Required with options: the build fails without it.
@options { value: string, label: string, icon?: string, checked?: boolean }[] The options, in place of the default slot. Each label is also its title.

Slots

NameDescription
legend The group's name, as one element, such as <span slot="legend">Color scheme</span>. Visually hidden. Required: the build fails without it.
default The option labels, when there are no options.

Tokens

The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.

Type a value to try it in every example above. Reset puts the default back.

Token Type Default Override
--norn-ui-accentThe brand color, shared by every component. <color> #2346d4
--norn-ui-border-radiusCorner radius. <length> 6px
--norn-ui-focus-widthFocus ring width. One ring on every focusable element. <length> 2px
--norn-ui-focus-offsetGap between an element and its focus ring. An element the ring would clip draws it inset, at the negative of this. <length> 2px
--norn-ui-state-hoverShare of the text color mixed into the background while the pointer is over a control. <percentage> 8%
--norn-ui-state-pressShare of the text color mixed into the background while a control is pressed, and of the accent on a selected or current item. <percentage> 12%
--norn-ui-motion-durationLength of a state change, such as a hover layer. <time> 150ms
--norn-ui-motion-easingEasing for every transition. <easing-function> cubic-bezier(0.2, 0, 0, 1)
--norn-ui-motion-slideLength of a selected state sliding to a new option, such as a checked segment or a selected tab. <color> 200ms
--norn-ui-motion-trailHow far the trailing edge of a sliding selected state lags its leading edge, so the shape stretches as it moves. <color> 90ms
--norn-ui-control-heightHeight of a button, field, or tab. A component raises it to 2.75rem for a coarse pointer. <length> 2.25rem
--norn-surface-raisedRaised surface. <color> light-dark(hsl(40, 14%, 96%), #242932)
--norn-text-mutedSecondary text color. <color> light-dark(#4b5160, #a4abba)
--norn-text-accentThe accent for text and links: darkened in light mode, lightened in dark mode. The lightness caps keep any accent at 4.5:1 or better. <color> light-dark(oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 82%, black) min(l, 0.5) c h), oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 55%, white) max(l, 0.72) c h))
--norn-space-2xsSmallest spacing step. <length> 0.25rem
--norn-space-sSmall spacing step. <length> 0.75rem