3.0.0 • Published 4 years ago

@19h47/radios v3.0.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

@19h47/radios

Usage

HTML

<div class="js-radios" role="radiogroup">
	<div class="js-radio" aria-checked="true" tabindex="0" role="radio">
		<span>Option 1</span>
		<input type="radio" id="option_1" name="option" value="option_1" checked style="display: none;">
	</div>

	<div class="js-radio" 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>

JavaScript

const element = document.querySelector('.js-radios');
const radios = new Radios(element);

radios.init();

With events

import Radios from '@19h47/radios';

const element = document.querySelector('.js-radios');
const radios = new Radios(element);

radios.inputs.map(input => {
	input.addEventListener('Radio.activate', event => {
		const { detail: { element } } = event;

		console.log(item);
	});
});

Keyboard Support

KeyFunction
TabMoves keyboard focus to radiogroup.
ArrowMoves up and down radio options.
HomeMove to first input.
EndMove to last input.

ARIA Roles, Properties and States

RoleProperty/StateUsage
RadiogroupIdentify div as a container for radios
Radioaria-checkedIndicate state of radio:- Checked (e.g. aria-checked=true)- Unchecked (e.g. aria-checked=false)
aria-labelledbyUsed to identify radio group

Events

EventArgumentsDescription
Radio.activateevent
3.0.0

4 years ago

2.1.4

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago