How to use -axxy-
Start with ordinary, labelled HTML and standard W3C ARIA roles and states, then place the markup inside an <axxy-scope> wrapper. The examples below are live: try their controls, then use the accompanying markup and application code in your own page.
Initialize the library
Import the full entry point once from your application module. It registers the available plugins before defining the wrapper, so existing wrappers initialize when the module loads. See Installation for project setup.
<axxy-scope>
<button type="button" aria-pressed="false">Favorite</button>
</axxy-scope>
<script type="module" src="/app.js"></script>
// app.js — adjust the relative path to your project.
import './axxy/index.js';
Use native elements such as button, input, table, and dialog whenever they fit. Authors still provide accessible names, headings, meaningful content, and visible focus styles. The library supplies the selected pattern’s states and interactions; it does not decide what an application action should do.
Standard implicit and explicit W3C roles and ARIA attributes are the single source of truth. Simply wrap standard markup in <axxy-scope> without custom attributes. You only need to author the unavoidable ARIA attributes that define a component's API: if you provide extra aria-* attributes or ids, -axxy- preserves them; otherwise it generates missing ids and wires relationships like aria-controls, aria-labelledby, and aria-describedby automatically.
Style states and focus
The library does not import a theme. Include styles in your application that keep focus visible and distinguish state changes. The following sample reproduces the decorative flower and disabled appearance used below. The empty alternative text after the slash keeps the flower out of a toggle’s accessible name.
:focus-visible {
outline: 3px solid #6840b5;
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
[aria-pressed='true']::after {
content: '🌼' / '';
padding-left: .5rem;
}
button:disabled, [role='button'][aria-disabled='true'] {
color: #666;
background: #e7e7e7;
border: 2px dashed #999;
cursor: not-allowed;
}
Visual disabled styling is separate from behavior. Use the native disabled property when a native control should stop receiving focus and activation. The application handler in the next section shows how that state is set.
Buttons and toggles
A button activates an action. A toggle also maintains aria-pressed; its accessible name stays constant while its state changes. The flower on pressed toggles is a decorative style used by this documentation site.
Disables Show feedback and Favorite. Press again to enable them.
<axxy-scope>
<button type="button" id="axxy-btn">Show feedback</button>
<button type="button" aria-pressed="false" id="axxy-toggle">Favorite</button>
<button type="button" aria-pressed="false" id="axxy-disable"
aria-controls="axxy-btn axxy-toggle"
aria-describedby="disable-help">Disable example controls</button>
<p id="disable-help">Disables Show feedback and Favorite. Press again to enable them.</p>
<span id="click-feedback" aria-hidden="true" hidden>clicked!</span>
<p id="feedback" role="status"></p>
</axxy-scope>
The disable control demonstrates application behavior. The toggle plugin updates its pressed state; the following click handler reads that state and sets the targets’ native disabled properties. Neither the toggle state nor aria-controls disables other controls on its own.
// Register application handlers after importing axxy/index.js.
const button = document.getElementById('axxy-btn');
const toggle = document.getElementById('axxy-toggle');
const disable = document.getElementById('axxy-disable');
const feedback = document.getElementById('feedback');
button.addEventListener('click', () => {
feedback.textContent = 'Button activated.';
});
disable.addEventListener('click', () => {
const disabled = disable.getAttribute('aria-pressed') === 'true';
button.disabled = disabled;
toggle.disabled = disabled;
feedback.textContent = disabled
? 'Example controls disabled.'
: 'Example controls enabled.';
});
const clickFeedback = document.getElementById('click-feedback');
let feedbackTimer;
for (const control of [button, toggle]) {
control.addEventListener('click', () => {
clearTimeout(feedbackTimer);
clickFeedback.hidden = false;
feedbackTimer = setTimeout(() => { clickFeedback.hidden = true; }, 1000);
});
}
Native disabled buttons stop receiving focus and activation. Keep a control enabled when users need it to restore the others. See the dedicated button example for additional custom-control variations.
Checkboxes
A native checkbox retains its browser behavior and form value. A custom checkbox supports checked, unchecked, and mixed states with Space activation. Supply an explicit label or readable text.
Partial selection example<axxy-scope>
<label><input type="checkbox" name="updates"> Email updates</label>
<span role="checkbox" aria-checked="mixed">Partial selection example</span>
</axxy-scope>
The custom example shows an initial mixed state; it is not connected to the Email updates checkbox. See the mixed-state group example for a controller that reflects several related checkboxes.
Accordion
Place each trigger button in an appropriate heading directly before its panel. Enter or Space toggles a panel; arrow keys move between header buttons. -axxy- generates missing ids and wires aria-controls and aria-expanded automatically.
Use ordinary HTML inside an -axxy- wrapper.
Press Enter or Space to expand a section. Arrow keys move between its headings.
<axxy-scope>
<section aria-labelledby="accordion-title" aria-roledescription="accordion">
<h2 id="accordion-title">Project information</h2>
<h3><button aria-expanded="true">About</button></h3>
<div><p>Initially expanded content.</p></div>
<h3><button>Keyboard support</button></h3>
<div><p>Initially collapsed content.</p></div>
</section>
</axxy-scope>
See the accordion example for a complete form organized into sections.
Tabs
Group tab buttons in a named role="tablist" followed by their panels. -axxy- pairs tabs to panels automatically and wires role="tab", role="tabpanel", aria-controls, and aria-labelledby. The default automatic mode changes the selected tab as arrow keys move focus.
Arrow keys change the selected tab. Home and End move to the first and last tab.
Add class="manual" to the tablist to select with Enter or Space.
<axxy-scope>
<section aria-label="Project information">
<div role="tablist" aria-label="Project information">
<button>Overview</button>
<button>Details</button>
</div>
<div><p>Overview content.</p></div>
<div><p>Details content.</p></div>
</section>
</axxy-scope>
Add class="manual" to the tablist when focus and selection should be separate. Compare the automatic and manual examples.
Tooltip
A tooltip supplements a control’s name. Place a role="tooltip" element directly after its trigger (or link it explicitly with aria-describedby). It appears on focus or hover, remains available while hovered, and dismisses with Escape.
<axxy-scope>
<button type="button">Keyboard help</button>
<span role="tooltip">Use Tab to move between controls. Press Escape to dismiss this hint.</span>
</axxy-scope>
Modal dialog
Use a native dialog with a heading. Place its opener button directly before the dialog (or reference a remote dialog with aria-controls). Native modality prevents interaction with the rest of the page; the plugin wires missing IDs and supports focus wrapping and return to the opener.
<axxy-scope>
<button type="button">Edit display name</button>
<dialog>
<h2>Display name</h2>
<label>Name <input autocomplete="nickname" autofocus></label>
<button type="button">Close</button>
</dialog>
</axxy-scope>
This example edits the field locally; saving a name requires your application’s handler. See the dialog example for a longer workflow.
Interactive grid
Use a grid when the content needs directional keyboard navigation and interactive cells. A static table usually needs only native table markup.
Use arrow keys to move between cells. Enter or F2 enters an editor; Escape returns to navigation. Home and End move within a row; Control with Home or End moves across the grid.
| Name | Updates | Team |
|---|---|---|
| Sam | Enabled | Engineering |
<axxy-scope>
<p id="grid-help">Arrow keys navigate. Enter/F2 edits; Escape returns to navigation.</p>
<table role="grid" aria-describedby="grid-help">
<caption>Team settings</caption>
<thead><tr>
<th scope="col">Name</th>
<th scope="col">Updates <button type="button" id="grid-header-button">Button</button></th>
<th scope="col">Team</th>
</tr></thead>
<tbody>
<tr>
<td><input aria-label="First name" value="Alex"></td>
<td><input type="checkbox" aria-label="Updates for Alex"></td>
<td><select aria-label="Team for Alex"><option>Design</option><option>Engineering</option></select></td>
</tr>
<tr><td>Sam</td><td>Enabled</td><td>Engineering</td></tr>
</tbody>
</table>
</axxy-scope>
The extra button in the live grid’s Updates header uses an application handler to write “Grid header button activated.” to the feedback status above. Grid navigation makes that native button reachable without replacing its activation behavior.
document.getElementById('grid-header-button').addEventListener('click', () => {
document.getElementById('feedback').textContent = 'Grid header button activated.';
});
Explore sorting, editing, and column visibility in data grids, or collections of controls in layout grids.
Dynamic (opt-in observe)
By default, <axxy-scope> initializes once on mount with zero background observation overhead. Add the opt-in observe attribute when you want a wrapper to automatically scan newly inserted DOM nodes and enhancement attributes after the current JavaScript task.
<axxy-scope observe>
<button type="button" id="create-btn-auto">Add toggle</button>
<button type="button" id="clear-auto">Clear added toggles</button>
<div id="dyn-host-auto"></div>
</axxy-scope>
The following helper is shared by all three dynamic examples.
function createToggle(label) {
const button = document.createElement('button');
button.type = 'button';
button.textContent = label;
button.setAttribute('aria-pressed', 'false');
return button;
}
let count = 0;
const host = document.getElementById('dyn-host-auto');
document.getElementById('create-btn-auto').addEventListener('click', () => {
host.append(createToggle(`Dynamic toggle ${++count}`));
});
document.getElementById('clear-auto').addEventListener('click', () => {
host.replaceChildren();
});
Dynamic (with wrappers)
Each new toggle has its own <axxy-scope> wrapper, which initializes it when connected. The host below is intentionally outside every wrapper, so each inserted wrapper owns its own descendants.
<axxy-scope>
<button type="button" id="create-btn">Create</button>
<button type="button" id="clear">Clear</button>
</axxy-scope>
<div id="dyn-host"></div>
// Uses createToggle from the automatic example.
let wrappedCount = 0;
const wrappedHost = document.getElementById('dyn-host');
document.getElementById('create-btn').addEventListener('click', () => {
const wrapper = document.createElement('axxy-scope');
wrapper.append(createToggle(`Wrapped toggle ${++wrappedCount}`));
wrappedHost.append(wrapper);
});
document.getElementById('clear').addEventListener('click', () => {
wrappedHost.replaceChildren();
});
Dynamic (rescan)
New toggles share one default wrapper (no observe attribute). Calling rescan() initializes each toggle immediately and synchronously. Use it when mutating children inside a deterministic wrapper, when the next statement needs the enhanced state, or after registering an additional plugin. Repeated scans do not add duplicate handlers.
<axxy-scope id="my-x">
<button type="button" id="create-btn-2">Create</button>
<button type="button" id="clear-2">Clear</button>
<div id="dyn-host-2"></div>
</axxy-scope>
// Uses createToggle from the automatic example.
let rescannedCount = 0;
const rescanHost = document.getElementById('dyn-host-2');
const sharedWrapper = document.getElementById('my-x');
document.getElementById('create-btn-2').addEventListener('click', () => {
rescanHost.append(createToggle(`Rescanned toggle ${++rescannedCount}`));
sharedWrapper.rescan();
});
document.getElementById('clear-2').addEventListener('click', () => {
rescanHost.replaceChildren();
});
Events and application integration
-axxy- decouples accessibility logic (keyboard navigation, focus loops, and ARIA state updates) from your application's business logic. Rather than requiring callback props or framework-specific APIs, the library dispatches standard DOM events and bubbling CustomEvents.
All custom events are dispatched with bubbles: true, allowing you to listen directly on the target control, delegate to the parent <axxy-scope> wrapper, or listen globally on document.
Custom events reference
| Component | Event Name | Target Element | event.detail Payload |
Cancelable |
|---|---|---|---|---|
| Accordion | axxy-accordion-change |
Header <button> |
{ expanded: boolean, trigger: HTMLElement, panel: HTMLElement } |
No |
| Tabs | axxy-tab-change |
Selected [role="tab"] |
{ tab: HTMLElement, panel: HTMLElement } |
No |
| Disclosure | axxy-disclosure-change |
Trigger <button> |
{ expanded: boolean, panel: HTMLElement } |
No |
| Menu / Menubar | axxy-menu-select |
Chosen [role="menuitem"] |
{ item: HTMLElement, value: string, checked: string|null } |
Yes (suppresses default navigation) |
| Listbox | axxy-listbox-change |
[role="listbox"] |
{ selected: HTMLElement[] } |
No |
| Listbox (Reorder) | axxy-listbox-reorder |
[role="listbox"] |
{ message: string } |
No |
| Treeview | axxy-tree-select |
[role="tree"] |
{ item: HTMLElement, label: string } |
No |
| Radio Group | axxy-radio-change |
Checked [role="radio"] |
{ item: HTMLElement, value: string } |
No |
| Toolbar | axxy-toolbar-change |
Active control | { item: HTMLElement } |
No |
| Slider | axxy-slider-change |
<input type="range"> |
{ value: number } |
No |
| Spinbutton | axxy-spinbutton-change |
<input type="number"> |
{ value: number } |
No |
| Sortable Table | axxy-sort |
<table> |
{ column: number, ascending: boolean } |
No |
| Feed | axxy-feed-load |
[role="feed"] |
None (indicates loading threshold reached) | No |
Note: Native controls (buttons, checkboxes, sliders, dialogs) also fire standard browser events: click, input, change, and close.
Listening to events
You can listen directly on individual controls or take advantage of event bubbling to delegate listeners on the <axxy-scope> root or document:
// 1. Listen for tab activation to load view content dynamically
document.addEventListener('axxy-tab-change', (event) => {
const { tab, panel } = event.detail;
console.log('Active tab:', tab.textContent.trim(), 'Panel:', panel.id);
});
// 2. Listen for accordion toggles
document.addEventListener('axxy-accordion-change', (event) => {
const { expanded, trigger, panel } = event.detail;
console.log(`Section ${trigger.textContent.trim()} is now ${expanded ? 'open' : 'closed'}`);
});
// 3. Listen for menu selection with optional cancellation
document.addEventListener('axxy-menu-select', (event) => {
const { item, value } = event.detail;
if (value === 'danger-action' && !confirm('Proceed?')) {
event.preventDefault(); // Cancel default navigation
return;
}
handleMenuAction(value);
});
Choose the pattern your interface needs
Each component in the Components navigation provides a dedicated page with keyboard guidance, events, and source markup for the remaining patterns, including disclosure navigation, comboboxes, listboxes, date pickers, and carousels.
Consult References for the W3C guidance behind these implementations and Contributing for the component contract and verification workflow.