@19h47/switch 中文文档教程

发布于 3年前 浏览 27 项目主页 更新于 3年前

@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.
SpaceToggle switch between checked and unchecked.

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

@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.
SpaceToggle switch between checked and unchecked.

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

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文