yarn add @19h47/radiogroup
<div role="radiogroup">
<div aria-checked="true" tabindex="0" role="radio">
<span>Option 1</span>
<input
id="option_1"
type="radio"
name="option"
value="option_1"
checked
style="display: none;"
/>
</div>
<div aria-checked="false" tabindex="-1" role="radio">
<span>Option 2</span>
<input type="radio" id="option_2" name="option" value="option_2" style="display: none;" />
</div>
</div>
import RadioGroup from '@19h47/radiogroup';
const $element = document.querySelector('[role="radiogroup"]');
const radiogroup = new RadioGroup($element);
radiogroup.init();
Key | Function |
---|---|
Tab |
|
Down arrow |
|
Home | Move to first input. |
Up arrow |
|
End | Move to last input. |
Space | If the radio button with focus is unchecked, it's state will be changed to checked. |
Role | Property/State | Usage |
---|---|---|
radiogroup |
|
|
radio | aria-checked | Indicate state of radio:
|
aria-labelledby | Used to identify radio group |
Event Name | Description |
---|---|
Radio.activate | Return an event object containing detail object (current element and current value) |
Radio.deactivate | Return an event object containing detail object (current element and current value) |
import RadioGroup from '@19h47/radiogroup';
const $element = document.querySelector('[role="radiogroup"]');
const radiogroup = new RadioGroup($element);
radiogroup.init();
radiogroup.radios.forEach(radio => {
radio.el.addEventListener('Radio.activate', ({ detail }) => {
console.log(detail.element, detail.value);
});
radio.el.addEventListener('Radio.deactivate', ({ detail }) => {
console.log(detail.element, detail.value);
});
});
Option | Type | Default | description |
---|---|---|---|
tagger | array | [] |
|
template | function | () => {} |
|
name | string | '' |
Method | Description | Arguments |
---|---|---|
init() |
||
destroy() |
Method | Description | Arguments |
---|---|---|
activate() |
Active a given radio |
true |
deactivate() |
||
destroy() |
# install dependencies
$ yarn install
# serve with hot reload at localhost:3000
$ yarn serve
# build for development
$ yarn dev
# build for production
$ yarn build