yarn add @19h47/switch
<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>
import Switch from '@19h47/switch';
const $switch = document.querySelector('[role="switch"]');
const switchButton = new Switch($switch);
switchButton.init();
Key | Function |
---|---|
Tab |
|
Space Enter |
|
Event | Arguments | Description |
---|---|---|
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');
});