1.0.0 • Published 7 months ago

@19h47/switch v1.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
7 months ago

@19h47/switch

Installation

yarn add @19h47/switch

HTML

<div tabindex="0" aria-checked="false" role="switch">
	<span>Toggle this switch element</span>
	<span></span>
	<div style="display: none;"><input type="checkbox" /></div>
</div>

JavaScript

import Switch from '@19h47/switch';

const $switch = document.querySelector('[role="switch"]');

const switchButton = new Switch($switch);
switchButton.init();

Keyboard support

KeyFunction
TabMoves keyboard focus to the switch.
SpaceEnterToggle switch between on and off.

Event

EventArgumentsDescription
Switch.activate
Switch.deactivate
import Switch from '@19h47/switch';

const $switch = document.querySelector('[role="switch"]');

const switchButton = new Switch($switch);
switchButton.init();

switchButton.on('Switch.deactivate', () => {
	console.log('deactivated');
});

switchButton.on('Switch.activate', () => {
	console.log('activated');
});

Acknowledgment

1.0.0

7 months ago

0.2.0

7 months ago

0.1.3

10 months ago

0.1.2

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.0

4 years ago