@19h47/spinbutton 中文文档教程

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

@19h47/spinbutton

旋转按钮是一种输入小部件,它将其值限制为一组或一组离散值。

HTML

<div role="spinbutton" aria-valuemin="0" aria-valuemax="100" aria-valuenow="10">
    <button class="js-decrease" tabindex="-1" aria-label="decrease" type="button">-</button>

    <input type="number" />

    <button class="js-increase" tabindex="-1" aria-label="increase" type="button">+</button>
</div>

JavaScript

import SpinButton from '@19h47/spinbutton';

const $element = document.querySelector('[role="spinbutton"]');
const spinbutton = new SpinButton($element);

spinbutton.init();

Events

EventArgsDescription
SpinButton.changevalueReturn the current activate value
import SpinButton from '@19h47/spinbutton';

const $element = document.querySelector('[role="spinbutton"]');
const spinbutton = new SpinButton($element);

spinbutton.init();

spinbutton.on('SpinButton.change', value => {
    console.log(value);
});

Options

OptionType
textobjectObject containing single and plural text. Can be set as data attribute data-spinbutton-text

Keyboard Support

旋转按钮提供旋转按钮设计模式中描述的以下键盘支持。

KeyFunction
Down ArrowDecreases value 1 step.
Up ArrowIncreases the value 1 step.
Page DownDecreases the value 5 steps.
Page UpIncreases the value 5 steps.
HomeDecreases to mimimum value.
EndIncreases to maximum value.

Role, Property, State, and Tabindex Attributes

RoleAttributeElementUsage
spinbuttondivIdentifies the div element as a spinbutton.

References

WAI-ARIA 创作实践 1.1 中的旋转按钮设计模式

@19h47/spinbutton

A spinbutton is an input widget that restricts its value to a set or range of discrete values.

HTML

<div role="spinbutton" aria-valuemin="0" aria-valuemax="100" aria-valuenow="10">
    <button class="js-decrease" tabindex="-1" aria-label="decrease" type="button">-</button>

    <input type="number" />

    <button class="js-increase" tabindex="-1" aria-label="increase" type="button">+</button>
</div>

JavaScript

import SpinButton from '@19h47/spinbutton';

const $element = document.querySelector('[role="spinbutton"]');
const spinbutton = new SpinButton($element);

spinbutton.init();

Events

EventArgsDescription
SpinButton.changevalueReturn the current activate value
import SpinButton from '@19h47/spinbutton';

const $element = document.querySelector('[role="spinbutton"]');
const spinbutton = new SpinButton($element);

spinbutton.init();

spinbutton.on('SpinButton.change', value => {
    console.log(value);
});

Options

OptionType
textobjectObject containing single and plural text. Can be set as data attribute data-spinbutton-text

Keyboard Support

The spin buttons provide the following keyboard support described in the spin button design pattern.

KeyFunction
Down ArrowDecreases value 1 step.
Up ArrowIncreases the value 1 step.
Page DownDecreases the value 5 steps.
Page UpIncreases the value 5 steps.
HomeDecreases to mimimum value.
EndIncreases to maximum value.

Role, Property, State, and Tabindex Attributes

RoleAttributeElementUsage
spinbuttondivIdentifies the div element as a spinbutton.

References

Spin Button Design Pattern in WAI-ARIA Authoring Practices 1.1

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