5.0.5 • Published 3 months ago

@19h47/checkbox v5.0.5

Weekly downloads
13
License
ISC
Repository
github
Last release
3 months ago

@19h47/checkbox

Install

yarn add @19h47/checkbox

HTML

<div role="checkbox" aria-checked="false">
	<button type="button" tabindex="-1">Do you want to click me?</button>
	<div style="display: none;">
		<input id="option" name="option" value="false" type="checkbox" />
	</div>
</div>

JavaScript

import Checkbox from '@19h47/checkbox';

const $checkbox = document.querySelector('[role="checkbox"]');
const checkbox = new Checkbox($checkbox);

checkbox.init();

Keyboard Support

KeyFunction
TabMoves keyboard focus to the checkbox.
SpaceToggles checkbox between checked and unchecked states.

Role, Property, State, and Tabindex Attributes

RoleAttributeElementUsage
h3Provides a grouping label for the group of checkboxes.
groupdivIdentifies the div element as a group container for the checkboxes.
aria-labelledbydivThe aria-labelledby attribute references the id attribute of the h3 element to define the accessible name for the group of checkboxes.
checkboxdivIdentifies the div element as a checkbox.The child text content of this div provides the accessible name of the checkbox.
tabindex="0"divIncludes the checkbox in the page tab sequence.
aria-checked="false"divIndicates the checkbox is not checked.
aria-checked="true"divIndicates the checkbox is checked.

Methods

MethodDescriptionArguments
activate()Activate the checkboxtrigger (optional) Whether or not the event should be trigger. Default to true
deactivate()Deactivate the checkboxtrigger (optional) Whether or not the event should be trigger. Default to true
import Checkbox from '@19h47/checkbox';

const $checkbox = document.querySelector('[role="checkbox"]');
const checkbox = new Checkbox($checkbox);

checkbox.init();

checkbox.activate();
checkbox.deactivate();

Event

Activate

import Checkbox from '@19h47/checkbox';

const $checkbox = document.querySelectorAll('[role="checkbox"]');
const checkbox = new Checkbox($checkbox);

checkbox.init();

checkbox.$input.addEventListener('activate', event => {
	const {
		target: { value },
	} = event;

	console.log(value); // Current activate value
});

Deactivate

import Checkbox from '@19h47/checkbox';

const $checkbox = document.querySelectorAll('[role="checkbox"]');
const checkbox = new Checkbox($checkbox);

checkbox.init();

checkbox.$input.addEventListener('deactivate', event => {
	const {
		target: { value },
	} = event;

	console.log(value); // Current deactivate value
});

CheckboxGroup

The CheckboxGroup is a wrapper class around Checkbox.

When a user clicks a checkbox, holds Shift, and then clicks another checkbox a few rows down, all the checkboxes inbetween those two checkboxes should be checked.

<div role="group">
	<div tabindex="0" role="checkbox" aria-checked="false">
		<button type="button" tabindex="-1"></button>
		Curst
		<div style="display: none;">
			<input id="curst" name="curst" value="Curst" type="checkbox" />
		</div>
	</div>

	<div tabindex="0" role="checkbox" aria-checked="false">
		<button type="button" tabindex="-1"></button>
		Doppelganger, Greater
		<div style="display: none;">
			<input
				id="doppelganger-greater"
				name="city-of-splendors[]"
				value="Doppelganger, greater"
				type="checkbox"
			/>
		</div>
	</div>

	<div tabindex="0" role="checkbox" aria-checked="false">
		<button type="button" tabindex="-1"></button>
		Duhlarkin
		<div style="display: none;">
			<input id="duhlarkin" name="city-of-splendors[]" value="Duhlarkin" type="checkbox" />
		</div>
	</div>
</div>
import { CheckboxGroup } from '@19h47/checkbox';

const $element = document.querySelector('[role="group"]');
const checkboxgroup = new CheckboxGroup($element);

checkbox.init();

Example

An example is located right here, see sources.

References

5.0.5

3 months ago

5.0.4

7 months ago

5.0.1

7 months ago

5.0.0

7 months ago

4.5.4

10 months ago

4.5.5

8 months ago

4.6.0

8 months ago

4.5.3

1 year ago

4.5.0

1 year ago

4.5.2

1 year ago

4.5.1

1 year ago

0.0.0

1 year ago

4.4.1

2 years ago

4.4.0

3 years ago

4.3.0

3 years ago

4.2.1

3 years ago

4.2.0

3 years ago

4.1.1

3 years ago

4.1.0

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.5

4 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.11

5 years ago

1.0.10

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago