7.0.4 • Published 1 month ago

@19h47/radiogroup v7.0.4

Weekly downloads
19
License
ISC
Repository
github
Last release
1 month ago

@19h47/radiogroup

Install

yarn add @19h47/radiogroup

Usage

HTML

<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>

JavaScript

import RadioGroup from '@19h47/radiogroup';

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

radiogroup.init();

Keyboard Support

KeyFunction
TabMoves keyboard focus to the checked radio button in a radiogroup.If no radio button is checked, focus moves to the first radio button in the group.
Down arrowMoves focus to next radio button in the group.If focus is on the last radio button in the group, move focus to the first radio button.
HomeMove to first input.
Up arrowMoves focus to previous radio button in the group.If focus is on the first radio button in the group, move focus to the last radio button.
EndMove to last input.
SpaceIf the radio button with focus is unchecked, it's state will be changed to checked.

ARIA Roles, Properties and States

RoleProperty/StateUsage
radiogroupThe role="radiogroup" attribute identifies the div element as a container for a group of radio buttons.The descendent radio buttons are considered part of the group.The accessible name comes the aria-labelledby attribute, which points to the element that contains the label text.The radiogroup widget does not need a tabindex value, since the ul[role"radiogroup"] element never receives keyboard focus.
radioaria-checkedIndicate state of radio:Checked (e.g. aria-checked=true)Unchecked (e.g. aria-checked=false)
aria-labelledbyUsed to identify radio group

Events

Event NameDescription
Radio.activateReturn an event object containing detail object (current element and current value)
Radio.deactivateReturn 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);
	});
});

Options

OptionTypeDefaultdescription
taggerarray[]
templatefunction() => {}
namestring''

RadioGroup Methods

MethodDescriptionArguments
init()
destroy()

Radio Methods

MethodDescriptionArguments
activate()Active a given radioshouldFocus (optional)Default to true
deactivate()
destroy()

Build Setup

# install dependencies
$ yarn install

# serve with hot reload at localhost:3000
$ yarn serve

# build for development
$ yarn dev

# build for production
$ yarn build

References

7.0.4

1 month ago

7.0.3

3 months ago

5.5.0

7 months ago

6.0.1

7 months ago

6.0.3

7 months ago

6.0.2

7 months ago

7.0.0

7 months ago

7.0.2

7 months ago

7.0.1

7 months ago

5.4.7

7 months ago

5.4.6

10 months ago

5.4.5

12 months ago

5.4.4

12 months ago

5.4.3

2 years ago

5.4.2

2 years ago

5.4.1

3 years ago

5.4.0

3 years ago

5.3.1

3 years ago

5.3.0

3 years ago

5.2.2

4 years ago

5.2.0

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.2.5

4 years ago

4.2.4

4 years ago

4.1.3

4 years ago

4.1.2

4 years ago

4.0.1

4 years ago

4.0.2

4 years ago

4.0.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago