The hard part of a dialog, already written

7 min·Assumes: nothing

Drawing a dialog is quick. Then Escape does nothing. Focus slips out behind it. A screen reader never hears it open.

@markless/ui writes that part for you. It gives you menus, dialogs, pickers and tabs that already handle the keyboard, focus and screen readers. It gives you no colours, fonts or spacing. You bring those with your own CSS.

People call a library like this headless. It has the behaviour, and the look is yours.

A dialog with no handlers

Click Edit address. Press Tab a few times, then press Escape.

Open it, then use the keys

WatchClick Edit address. Press Tab a few times, then press Escape.
import { modal } from '@markless/ui';export default function EditAddress() @{	<modal.root>		<modal.trigger class="open">Edit address</modal.trigger>		<modal.backdrop class="backdrop">			<modal.content class="dialog">				<modal.title class="title">Edit delivery address</modal.title>				<modal.description class="desc">We will send your order here.</modal.description>				<modal.close class="close">Cancel</modal.close>			</modal.content>		</modal.backdrop>	</modal.root>}

The tab under the dialog is its whole file, without the <style> block.

Focus stayed inside the dialog while you pressed Tab. Escape closed it and put focus back on Edit address. You wrote none of that. The modal's own tests check it:

  • Escape closes the dialog and puts focus back on the trigger.
  • While it is open, the mouse, the keyboard and screen readers cannot reach the page behind it.
  • Tab never moves focus to the page behind it.
  • A screen reader announces modal.title as the dialog's name.

Families and parts

Each component is a family: a set of parts that work together. modal is one family, and modal.trigger, modal.content and modal.close are its parts. You write each part as a tag.

The root part holds the state, such as whether the dialog is open. The other parts read that state. Most of them also show it on their own element as a ui-* attribute, such as ui-open. That attribute is how you style them, and Styling covers it.

Which parts say it is open?

WatchClosed. No part has ui-open. Press the trigger, then Cancel or Escape.

Each part name is one lowercase word. accordion.itemtrigger is the trigger of one item. slider.valuelabel is the label that shows the slider's value.

Add it to your app

Install the package:

npm install @markless/ui

Then add its ui() plugin to vite.config.ts, next to markless():

import { defineConfig } from 'vite';
import { markless } from '@markless/core/vite';
import { ui } from '@markless/ui/vite';

export default defineConfig({
	plugins: [ui(), markless()],
});

ui() does two jobs. It turns icon tags, such as <lucide.check />, into inline SVG. It also tells Vite to leave the package alone, so Markless builds the families together with your own components. Vite runs ui() before markless() whatever order you list them in.

In a multi-page app built with the router, the list is [ui(), markless(), router()].

Import a family

Import a family by name from the package root. Its parts are properties on that name:

import { modal, select, tabs } from '@markless/ui';

Always import families from the package root in your components. The package also lists a path for most families, such as @markless/ui/tabs. The build rejects a value import from that path with MARKLESS_UI_IMPORT_SHAPE. A namespace import such as import * as ui from '@markless/ui' fails the same way. The root also exports icon packs, such as lucide.

It renders wherever your app does

A family is a Markless component, like the ones you write. So it runs wherever your app runs: in the browser alone, on a server, or inside a test. The package's own tests render every family both in the browser alone and from server HTML. A shared set of checks runs both ways.

Is it the same select?

render() in the browser aloneHTML from a server, then the browsera Vitest browser test
WatchSame select.root, same parts, same ui-open. render() built it in the browser.

Every family

There are 46 families. Each name links to its page where one exists. The rest have no page yet, but they ship in the package and you can import them today.

Family What it is
accordion Stacked sections. Each heading opens or closes its own panel.
base Small parts the families build on: button, label, separator and visuallyhidden. Root import only.
buttongroup A set of toggle buttons, such as text alignment or bold and italic.
calendar A month of days to pick a date from.
carousel Slides with back, forward, slide-picker and play controls.
checkbox One checkbox with a label, a description, an error and a form field.
checklist A group of checkboxes with a select-all box.
collapsible One trigger that shows or hides one panel.
colorpicker A colour picker with an area, channel tracks, a typed value and swatches.
combobox A text field with a list attached. Focus stays in the field.
crop A rectangle you move and resize inside an area, such as an image cropper.
datebox A date typed into three number boxes.
drawer A dialog that slides in from an edge and swipes back out.
editable Rename in place. A value shows as a button and edits in a text field.
fileupload A drop area, a browse button and a row for each chosen file.
gridlist A list of rich items, such as cards, where a row holds its own controls.
hovercard A card that shows when the pointer rests on its trigger or focus stays there. Root import only.
ink A freehand drawing area, such as a signature pad.
menu A menu that a button or a right-click opens, with submenus.
menubar An application menu bar, such as File, Edit and View.
modal A dialog that blocks the page behind it. It has an alert mode.
navbar The site's main navigation, with dropdown items.
numberbox One number in a text field, with two step buttons.
otp A one-time code shown as boxes over one real text field.
pad A control that picks an X and a Y value on one area.
pagination Page links with back and forward controls.
popover A panel that a trigger opens, placed next to that trigger.
progress A progress bar with a track, an indicator and a value label.
qrcode Draws a value as a QR code.
radiogroup A group of radio choices.
rating One number out of a row of marks, such as stars.
resizable Panels in a row or column with dividers you drag.
select A button that opens a list of options. You pick one.
slider A value or a range along a track, with one or two thumbs.
table Rows and columns with arrow-key movement, row selection and sort headers.
tabs A list of tabs. Each tab shows one panel.
taglist A row of text tags. Add taglist.input to type new ones.
textbox A labelled input or textarea with a description and an error.
timebox A time of day typed into separate hour and minute boxes.
toaster A region that shows short messages and reads them to screen readers.
toggle An on/off switch.
tokenbox Text with tokens inside it, such as mentions. Still early. Root import only.
toolbar A bar of controls that share one Tab stop.
tooltip A short description that shows on hover or keyboard focus.
tour A tour of steps that highlights elements on the page.
tree A nested tree, such as a file tree.

The package's own notes say tokenbox still waits on work in Markless itself. You can import it today, but expect it to change.

Next: give these parts a look in Styling.