Accessibility and keyboard
Make every action reachable from the keyboard and understandable to screen readers.
janelkit Included with janelkit. Nothing extra to install. What you will learn
- How keyboard focus moves through a window, and how to check it.
- How screen readers name controls, and when you must add a label.
- How to give a custom clickable box the right role.
- How to add keyboard shortcuts.
Who depends on this
Some people use only the keyboard; others hear the interface through a screen reader, a program that reads out each control. Both depend on two things your template decides: the order in which controls receive focus, and the name each control announces. Built-in controls handle most of this for you. Your job is to name things that have no visible text and to check the result.
Focus follows the template order
Tab and Shift+Tab move the keyboard focus through the controls in the order they appear in the template. A <column>, <row> or flex with on:click also joins that order and is activated with Space or Enter, like a button. The focused element always shows a ring in the --primary color; you can restyle it with an outline rule, but keep it visible.
tabindex={0} adds a box to the Tab order; tabindex={-1} removes it, although code can still focus it with a ref. disabled={True} on a box removes it from the order and ignores its events.
- Put the mouse away and reach every action with Tab, Shift+Tab, Space and Enter.
- Check that the order matches the visual order. If it does not, reorder the template.
- Check that you can always see where the focus is.
Every control needs a name
Screen readers announce a control’s text: the caption of a button, checkbox, option or tab, or the placeholder of an empty field. label="…" on any element sets or replaces that name. Use it on fields without visible text, on icon-only actions and on clickable cards. Images use alt to describe what they show.
<!-- query and note come from the script; open is a function. -->
<textfield bind:value={query} placeholder="Search…" label="Search notes" />
<row class="card" on:click={open(note)} label={f"Open {note['title']}"}>…</row>
<image src="logo.png" alt="Company logo" />CopyFragment · Add it to an existing component; it is not a complete file.
Common mistakes
- A clickable flex box, or one with as="button", that has no text or label produces a compile warning: a screen reader would not know what it is. A clickable <row> or <column> gets no such warning, so check those yourself.
- Color and position alone do not tell anyone what a control does.
Give custom boxes a role with as
When you build a control from a flex box, as tells the keyboard and screen readers what it is. It changes behavior and meaning, not appearance. A plain <button> is still the clearest choice for a simple action; use as when you build a tab, a menu item or a switch of your own.
| as | In the Tab order | Keyboard | Announced as |
|---|---|---|---|
| (none) | Only with on:click | Like button | Like button when clickable |
| box | No | — | Ignored |
| button | Yes | Space (on release) or Enter → on:click | <button> |
| link | Yes | Enter | Link |
| checkbox, switch | Yes | Space | <checkbox>, with checked |
| tab, menuitem, option | With tabindex | Space or Enter; arrows are yours to program with on:keydown | With selected |
| listitem, list, menu, tablist, dialog, heading, region | No | — | Its role |
<!-- muted is a Boolean state. -->
<flex as="switch" checked={muted} on:click={muted = not muted} label="Mute notifications" class="toggle">
<text>{"Muted" if muted else "Sound on"}</text>
</flex>CopyFragment · Add it to an existing component; it is not a complete file.
How it works
- as="switch" puts the box in the Tab order and makes Space activate it.
- checked={muted} tells the screen reader the current state and enables the :checked style.
- label gives the switch a stable name, while the <text> shows the current state.
Shortcuts for frequent actions
<shortcut keys="Ctrl+S" on:activate={save} /> listens to its window’s keyboard and takes no space. Keys are written as in Qt: Ctrl+Shift+N, F5, Esc. A <shortcut> inside an {#if} is only active while its branch exists. For keys inside a single field, use that field’s on:keydown instead.
<script lang="python">
from janelkit import state
saved = state(0)
</script>
<window title="Shortcuts" width={380} height={200}>
<column padding={24} gap={12}>
<shortcut keys="Ctrl+S" on:activate={saved += 1} />
<text>Press Ctrl+S. Saved {saved} times.</text>
</column>
</window>CopyComplete component · Save as src/App.janel in a scaffolded project.
What you should see
Each Ctrl+S increases the number, wherever the focus is in the window.
Learn moreForms and two-way binding ↗
Key points
- Tab order follows the template; keep focus visible.
- Name every control without visible text with label; describe images with alt.
- Use as on custom boxes and <shortcut> for frequent actions.
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.