Subtlyv0.1.1
HTML & CSS

HTML data attributes

The runtime is headless: it emits events and exposes state, but your components own rendering, ARIA, focus and open/closed state. Do not mount it over an existing component that already implements the same interaction.

Setup

import { createInteractions } from 'subtly';
import 'subtly/styles.css'; // Optional
const ix = createInteractions();
ix.start(); // Call after DOM is available, once per root.
// ix.stop(); // On application teardown (or Vite HMR disposal).

In React/Vue, start in a client-side mounted effect and stop in its cleanup. In Alpine/Livewire, start once at app level. The runtime observes inserted and removed DOM and changes to data-ix. Configuration attributes are read at mount; to change them, stop/start the instance or remove and re-add the behavior in separate DOM updates. Avoid overlapping runtime roots. Shadow roots require their own runtime.

Supported declarative behaviors

data-ix token Configuration Events / state
hover-intent data-ix-hover-delay, data-ix-close-delay ix:hover-enter, ix:hover-leave, data-ix-hovered
menu-aim data-ix-delay, data-ix-side (right/left/top/bottom) ix:menu-change (detail.key, detail.trigger), data-ix-active
tooltip-group data-ix-delay ix:tooltip-show (detail.text), ix:tooltip-hide
prefetch data-ix-delay; links marked data-ix-prefetch Browser prefetch hint
roving-focus data-ix-orientation (vertical/horizontal); data-ix-roving-item on children tabindex and keyboard navigation
validation Native input constraints ix:validation (detail.message), data-ix-invalid

All durations are milliseconds. Multiple tokens may be separated by spaces. Events bubble; use event.target to distinguish nested components. The runtime does not automatically implement a complete accessible menu or tooltip.

Hover intent

<div data-ix="hover-intent" data-ix-hover-delay="150">
  <button type="button">Preview</button>
</div>
[data-ix~="hover-intent"][data-ix-hovered] { outline: 2px solid currentColor; }

Use click and focus handlers separately for accessible interactive content; hover is an enhancement, not the only way to interact.

Safe triangle

<nav data-ix="menu-aim" data-ix-side="right" id="products-nav">
  <button type="button" data-ix-menu-trigger="products" aria-expanded="false" aria-controls="products">Products</button>
  <button type="button" data-ix-menu-trigger="solutions" aria-expanded="false" aria-controls="solutions">Solutions</button>
  <div id="products" data-ix-menu-panel="products" hidden>Product links</div>
  <div id="solutions" data-ix-menu-panel="solutions" hidden>Solution links</div>
</nav>
const nav = document.querySelector('#products-nav');
nav.addEventListener('ix:menu-change', ({detail}) => {
    for (const panel of nav.querySelectorAll('[data-ix-menu-panel]')) {
        panel.hidden = panel.dataset.ixMenuPanel !== detail.key;
    }
    for (const trigger of nav.querySelectorAll('[data-ix-menu-trigger]')) {
        trigger.setAttribute('aria-expanded', String(trigger.dataset.ixMenuTrigger === detail.key));
    }
});

Position the panel with your own CSS or floating utility. Add Escape, outside dismissal and appropriate keyboard navigation in your host component. Native button click supports Enter/Space. This adapter selects an active panel; it does not implement a full open/close state machine. For automatic placement flips, use the programmatic menuAim API with the actual placement.

Tooltip group

<div data-ix="tooltip-group" data-ix-delay="500">
  <button type="button" data-ix-tooltip="Edit" aria-label="Edit">Edit</button>
  <button type="button" data-ix-tooltip="Duplicate" aria-label="Duplicate">Duplicate</button>
</div>

Listen for ix:tooltip-show/hide to control your existing tooltip. Use textContent, not innerHTML, for tooltip text. Your tooltip must support Escape, accessible descriptions and hovering over the tooltip itself when applicable. The adapter only coordinates trigger timing.

Validation

<input type="email" required data-ix="validation" aria-describedby="email-error" id="email">
<p id="email-error" aria-live="polite"></p>
const email = document.querySelector('#email');
email.addEventListener('ix:validation', ({detail}) => {
    email.setAttribute('aria-invalid', String(Boolean(detail.message)));
    document.querySelector('#email-error').textContent = detail.message;
});

Native form submission validation remains active. Always validate on the server.

Prefetch

<nav data-ix="prefetch"><a href="/about" data-ix-prefetch>About</a></nav>

Only mark safe same-origin GET pages. Do not prefetch logout, checkout, token URLs or sensitive pages.

Roving focus

Use for composite widgets such as a toolbar with a documented arrow-key interaction model. Do not add to ordinary navigation links or forms.

<div role="toolbar" aria-label="Text alignment" data-ix="roving-focus" data-ix-orientation="horizontal">
  <button data-ix-roving-item>Left</button><button data-ix-roving-item>Center</button>
</div>

Custom behavior

const ix = createInteractions({ behaviors: {
    example(element) {
        const controller = new AbortController();
        element.addEventListener('click', () => console.log('Clicked'), {signal: controller.signal});
        return () => controller.abort();
    }
}});
ix.start();

Then use data-ix="example". Return a cleanup function for each behavior.

Programmatic-only utilities

Floating positioning, draft recovery, scroll lock, optimistic updates, undo, request cancellation, caching and motion remain explicit JavaScript APIs. They need element references, storage allowlists, application state or lifecycle ownership that cannot safely be inferred from markup. See README for the full API. Import floating separately from subtly/floating after installing @floating-ui/dom.

Search Subtly documentation

Popular pages
↑↓ to navigate↵ to openESC to close