npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@agencecinq/switch

v2.0.1

Published

Accessible, WAI-ARIA switch as a lightweight Web Component.

Downloads

168

Readme

@agencecinq/switch

Accessible, WAI-ARIA switch as a lightweight Web Component.

A switch is an on/off control that represents a binary setting. <cinq-switch> provides an accessible, keyboard-navigable interface following the ARIA switch pattern, reads its state from the markup, syncs an optional hidden checkbox, and dispatches events when toggled.

Implementation follows the WAI-ARIA Authoring Practices switch pattern. Inspired by @19h47/switch.

Installation

pnpm add @agencecinq/switch

Usage

Web Component (<cinq-switch>)

<cinq-switch role="switch" aria-checked="false" tabindex="0">
  <span class="label">Notifications</span>
  <span class="switch" aria-hidden="true"><span></span></span>
  <span class="on" aria-hidden="true">On</span>
  <span class="off" aria-hidden="true">Off</span>
  <div hidden>
    <input type="checkbox" tabindex="-1" aria-hidden="true" />
  </div>
</cinq-switch>
import "@agencecinq/switch";

When disabled, use disabled or aria-disabled="true" and tabindex="-1":

<cinq-switch role="switch" aria-checked="false" disabled aria-disabled="true" tabindex="-1">
  <span class="label">Disabled switch</span>
  <span class="switch" aria-hidden="true"><span></span></span>
  <div hidden>
    <input type="checkbox" tabindex="-1" aria-hidden="true" disabled />
  </div>
</cinq-switch>

Importing @agencecinq/switch registers the Web Component in the Custom Elements Registry (customElements.define('cinq-switch', Switch)). The browser upgrades every existing <cinq-switch> in the DOM automatically — no manual init() call required.

HTML is the source of truth. The component will not auto-set role, auto-migrate attributes, or warn about missing labels. Use an a11y linter (axe-core, Lighthouse) to catch invalid markup.

Required markup

| Attribute / element | Required | Role | | ------------------- | -------- | ---- | | <cinq-switch> | Yes | Host element with role="switch". | | role="switch" | Yes | Identifies the control as a switch. | | aria-checked | Yes | Current on/off state ("true" or "false"). | | tabindex="0" | Yes | Makes the switch keyboard-focusable (use -1 when disabled). | | Hidden input[type="checkbox"] | Optional | Form helper only — not the switch. Keep it in a hidden container, with tabindex="-1" and aria-hidden="true". | | aria-hidden="true" on On/Off text | Recommended | Decorative state labels must not appear in the accessible name (APG). |

Use [data-switch-input] instead of input[type="checkbox"] when you need a more specific selector.

The switch label must not change when its state changes — update decorative On/Off text only if it is marked aria-hidden="true".

Switch groups

When presenting multiple switches, wrap them in a <fieldset> with a <legend>, or in an element with role="group" and aria-labelledby pointing to the group label (APG).

Markup variants

| Variant | Markup | | ------- | ------ | | Visible label | Text inside <cinq-switch> | | aria-label | On the host when no visible label | | aria-labelledby | References an external visible label | | aria-describedby | Points to static help text | | Minimal | Host + label only — no slider, no checkbox | | Pre-checked | aria-checked="true" (+ optional checked for CSS) | | Form helper | [data-switch-input] or input[type="checkbox"] in <div hidden> | | Disabled | disabled + aria-disabled + tabindex="-1", or aria-disabled alone |

See the interactive docs for live examples of each variant.

API

| Attribute | Required | Description | | --------- | -------- | ----------- | | checked | No | Reflected state on the host — useful for styling the wrapper. | | disabled | No | Observed — syncs the hidden checkbox and blurs focus when set externally. Pair with aria-disabled="true" and tabindex="-1" in markup. |

| Method | Description | | ------ | ----------- | | activate(emit?) | Turns the switch on. | | deactivate(emit?) | Turns the switch off. | | toggle() | Toggles on/off. | | destroy() | Detaches listeners. |

Keyboard support

| Key | Function | | --- | -------- | | Tab | Moves keyboard focus to the switch (tabindex="0" in markup). | | Space | Toggles between on and off when focused. | | Enter | Toggles between on and off when focused (optional per APG). |

On focus / blur, a .focus class is toggled on the host:

cinq-switch.focus {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

Programmatic API

const $switch = document.querySelector("cinq-switch");

$switch.activate();
$switch.deactivate();
$switch.toggle();

activate() and deactivate() accept an optional emit argument (default true). Pass false to update state without dispatching an event.

Call destroy() when removing the element from the DOM to detach listeners.

Events

| Event | Cancelable | Detail | Description | | ----- | ---------- | ------ | ----------- | | switch:activate | Yes | { el } | Fired before the switch turns on. Cancel to abort. | | switch:deactivate | Yes | { el } | Fired before the switch turns off. Cancel to abort. |

import { EVENTS } from "@agencecinq/utils";

$switch.addEventListener(EVENTS.SWITCH_ACTIVATE, () => {
  console.log("activated");
});

$switch.addEventListener(EVENTS.SWITCH_DEACTIVATE, () => {
  console.log("deactivated");
});

Build setup

pnpm -C packages/switch build

Acknowledgments