Behaviors
Menus, selects, dialogs and tabs that work for everyone: zobacz/behaviors gives a component its roles, keyboard, focus, dismissal and positioning, so none of it is written by hand.
Why behaviors
A menu, a select or a dialog can look finished in a screenshot and still fail everyone who uses a keyboard or a screen reader: focus that does not move in, Escape that does nothing, a list the arrow keys cannot reach, a popup that leaves focus on the page behind it. Every hand-written copy fails in its own way, and each one is found late, by a person who cannot buy.
zobacz/behaviors does these parts once: roles and ARIA state, keyboard movement, focus, dismissal, modality and positioning. Each is tested in a real browser, with axe, and the tests are checked by breaking the behavior on purpose. Components bring the markup and the words; behaviors bring the rest.
All behaviors
Import each from zobacz/behaviors. A pattern is usually one behavior with a preset.
| Behavior | Call | What it does |
|---|---|---|
| Popover | popup('popover') | Non-modal panel next to its trigger; focus moves in, Escape, a press outside or Tab out close it. |
| Menu | popup('menu') | Menu button: arrows, Home/End and typeahead over items, Enter picks and closes, focus returns. |
| Submenu | popup('submenu') | A menu item that opens a menu beside it: ArrowRight opens, ArrowLeft and Escape go back, a pick closes both. |
| Dialog | popup('dialog') | Modal: the page behind is inert and still, Tab stays inside, focus returns to the opener. |
| Alert dialog | popup('alertDialog') | A decision: Escape closes, a press outside does not and the component hears it. |
| Select | popup('select') | A listbox that opens on the selected option; Space and Enter pick; typeahead. |
| Combobox | popup('combobox') | Type to filter; focus stays in the input, the active option follows the arrows. With inline: true the list is part of a dialog (a command palette). |
| Date picker | popup('datePicker') | A grid of days: Left and Right move a day, Up and Down a week. |
| Behavior | Call | What it does |
|---|---|---|
| Tabs | list('tabs') | One tab stop; arrows move and select; panels named by their tabs. |
| Toolbar | list('toolbar') | One tab stop; arrows move between controls. |
| Listbox | list('listbox') | Single or multiple selection, typeahead. |
| Radio group | list('radioGroup') | A switch of buttons: one tab stop on the checked radio, every arrow moves and checks, no typeahead. |
| Disclosure | disclosure() | Shows and hides a panel that find-in-page can still open. |
| Behavior | Call | What it does |
|---|---|---|
| Position | position(), place() | CSS anchor positioning first; otherwise flip and shift inside the viewport. data-side and size variables. |
| Layer stack | pushLayer(), removeLayer() | Escape closes the topmost layer; a press outside closes down to where it landed. |
| Modal | lockOutside() | Everything outside is inert and the page does not scroll. |
| Focus | recoverFocus(), trapTab(), focusFirst() | Keeps the keyboard user's place when a row is deleted; traps and returns focus. |
| Roving focus and typeahead | moveIndex(), typeahead() | Arrow, Home and End movement with wrapping, grids, disabled items and right-to-left. |
| Change details | onChange: 'method' | Every change names its reason and source and can be cancelled: the component decides. |
| Announce | announce() | Says a status to screen reader users without moving focus. |
How a behavior attaches and resumes
A zobacz page is rendered on the server and resumed in the browser without running the template again, and its handlers are attributes in the HTML. So a behavior holds no closures and no DOM references across that boundary. It has two halves: attrs(state, part), a pure function the template spreads onto each part (the same attributes on the server and in the browser), and browser code that a @client method calls with the event.
The state is one plain object in one signal (widget()): whether it is open, which item is highlighted, which are selected. It is part of the server render and comes back on resume like any signal. Nothing listens to the page until something opens: the layer stack adds its document listeners on the first open and removes them with the last close, so no component has to load early, and the behaviors ride in a chunk shared by the components that use them.
Build a component from behaviors
Pick the behavior for the pattern, create it once at module level, keep its state in one signal, spread attrs on each part, and route the wrapper's click and keydown to one @client method that calls handle(). Always render the popup element (closed, it is hidden), key items by id, name every popup, and style from data-state, data-highlighted, data-selected and data-side. The menu below is the one the framework's browser suite drives.
import { Z, client, createSignal } from 'zobacz';import { popup, widget } from 'zobacz/behaviors'; const actions = popup('menu');const ITEMS = [{ id: 'edit', label: 'Edit' }, { id: 'delete', label: 'Delete' }]; export default class ZActionsMenu extends Z { menu = createSignal(widget()); @client menuEvent(e: Event): void { const picked = actions.handle(this, this.menu, e); if (picked) this.run(picked.item); } @client run(item: string | null): void { /* the app's action */ } template() { const s = this.menu.get(); return ( <div onClick={(e: MouseEvent) => this.menuEvent(e)} onKeyDown={(e: KeyboardEvent) => this.menuEvent(e)}> <button type="button" {...actions.attrs(s, 'trigger')}>Actions</button> <div {...actions.attrs(s, 'popup')}> {ITEMS.map((it, i) => ( <button type="button" key={it.id} {...actions.attrs(s, 'item', { key: it.id, index: i })}>{it.label}</button> ))} </div> </div> ); }}Words come from the app
A store is in German, French or English; the framework cannot know which. So behaviors ship no words: a popup is named by its title or its trigger, and where a behavior needs a word (a name, an announcement), it takes it as a typed, required option, filled from the app's own labels.
Testing
The server's HTML of a broken widget looks exactly like a working one, so behaviors are tested in Chromium: each pattern's keyboard contract, focus return, a press outside, nested layers, right-to-left and an axe scan with every popup open and closed. Each test was checked by breaking its behavior on purpose and watching it fail. A component built from behaviors adds its own browser test for what it puts together: the skill lists a keyboard checklist per pattern and a test template.
Agent-ready UI
An assistant that helps a store owner fill a form should not have to read screenshots or guess at the page's markup: both break with every redesign and neither knows which choice is consequential. zobacz/behaviors/agent reads what the behaviors already know, from the page itself: each menu, select, combobox, dialog, tabs and disclosure with its accessible name, value and options, and every labelled form field.
snapshot() lists the controls with a stable ref, act() runs steps in order (open, close, choose, fill, check, uncheck, press) through the same clicks and inputs a person makes, query() lists options without opening a list, and observe() reports each change with its previous value, reason and source. A component's change hook sees source 'agent' and can cancel. Labels match whole, never in part.
The app marks what matters: data-agent-confirm on a control (and every submit button) needs a person, data-agent-secret (and every password) can be filled and is never read out, data-agent-hidden removes a region. The agent acts as the signed-in person, so the server refuses it whatever it would refuse them. The bridge is opt-in, loaded by a dynamic import only where an app asks for it, with WebMCP tools for a browser's own agent when the app passes webmcp: true.
onConnect(): void { void import('zobacz/behaviors/agent').then((a) => a.connectAgent({ webmcp: true }));} // An agent in the page, with the bridge connectAgent() returned:const { entries } = agent.snapshot();const result = await agent.act({ steps: [ { label: 'Email', action: 'fill', args: ['ada@example.com'] }, { label: 'Plan', action: 'choose', args: ['Growth'] }, { label: 'Place order', action: 'press' }, ], allow: ['Place order'], // the person approved the submit});For agents
The zobacz package ships an agent skill: skills/behaviors/SKILL.md, with a pattern table, worked examples, the API, the keyboard contracts and the testing guide as reference pages. Its examples are built and type-checked by the framework's tests. llms.txt on this site lists every framework page and reference in one file.