ARIA Checkboxes

Expected behaviors

The checkbox should be focusable using the keyboard, and toggle its checkable state when pressing the Spacebar or Enter key.

The 4X ARIA Checkbox module automatically configures all required ARIA attributes and focus handling, in strict accordance with the ARIA specification.

The following attributes are handled automatically by the Checkbox module:

  • role=checkbox
  • aria-checked
  • tabindex

Available attributes for checkbox elements:

  • data-check : May be set to "false", "true", or "mixed" to set the current state of a checkable control when rendered.
  • aria-disabled : When set to "true" on the triggering element, will automatically disable associated functionality.

Note: When dynamically disabling a triggering element, the 4X setDisabled() function should be used to set the disabled state of the triggering element. This will ensure proper background mapping.


$A.setDisabled(triggeringElement, boolean);

HTML syntax

Standard Unchecked

<div data-check >
  Markup with checkbox name
  <input hidden type="checkbox" name="OptionalBoundCheckbox" />
</div>

Standard Checked

<div data-check="true" >
  Markup with checkbox name
  <input checked hidden type="checkbox" name="OptionalBoundCheckbox" />
</div>

Standard Partially-Checked

<div data-check="mixed" >
  Markup with checkbox name
</div>

IMPORTANT: The focusable active element must not include any other exposed active elements, otherwise these will not be accessible to non-sighted screen reader users.

Whenever a hidden checkbox is embedded within the simulated control, it will automatically reflect the toggled state of the parent element. This makes it possible to implement custom toggle controls that can be submitted in the same manner as native form controls. This, however, is optional, and may be removed without having any negative impact on the functionality of the simulated toggle control.

JavaScript syntax

$A.setCheckbox( domNodeOrCSSSelectorForTriggeringElement , {
// Configure functionality key / value mappings
});

Parameters

  1. A DOM element or CSS selector to specify the triggering element
  2. A configuration map to customize behaviors and options

Configuration

{

// Set an explicit name for the checkbox.
// If undefined, the accessible name will default to the text content within the checkbox element.
label: "My informative checkbox label",

// Specify if the checkbox is required.
// If a native checkbox element is specified, this property will automatically be set to match the checkbox element's 'required' property.
required: false,

// Specify if the checkbox is disabled.
// If a native checkbox element is specified, this property will automatically be set to match the checkbox element's 'disabled' property.
disabled: false,

// Set the class to be applied when a checkbox is checked.
// If undefined, "checked" will be set by default.
toggleClassName: "checked",

// Set the class to be applied when a checkbox is partially-checked.
// If undefined, "partially-checked" will be set by default.
partialClassName: "partially-checked",

// Set a custom event handler to process every time a checkbox is activated.
onActivate: function(ev, triggerNode, boundCheckbox, checked, set) {
// 'checked' reflects the current attribute value for the checkable item, and is always a number if applicable.
// if 0, the checked state is "false".
// if 1, the checked state is "true".
// if 2, the checked state is "mixed".
// The 'set' argument is a function that will set the checkable item to a new state.
// The new value must be a string consisting of "false", "true", or "mixed".
if (checked) {
set("false");
} else {
set("true");
}
ev.preventDefault();
}

}