Champ de formulaire utilisé pour sélectionner une ou plusieurs valeurs dans la liste.
Documentation : Figma
Langage: HTML
<div role="group" aria-labelledby="legend_502832276" class="checkbox-mixed class-1 class-2">
<div class="legend-container class-1 class-2">
<p class="form-legend" id="legend_502832276">Légende du groupe<span class="required"> *</span><span class="sr-only">, Message d'aide à la saisie</span></p>
<p aria-hidden="true" class="help-block" id="help-checkbox-mixed_940877476">
Message d'aide à la saisie
</p>
</div>
<div role="checkbox" class="checkbox-mixed-controler" aria-checked="true" aria-controls="checkbox-mixed_9408774760 checkbox-mixed_9408774761 checkbox-mixed_9408774762 checkbox-mixed_9408774763 " tabindex="0">Libellé du groupe d'éléments</div>
<div class="checkbox-group">
<div class="form-check with-checked-bg">
<input class="form-check-input" id="checkbox-mixed_9408774760" name="form-checkbox_676265104" type="checkbox" value="checkbox-value_935029038">
<label class="form-check-label" for="checkbox-mixed_9408774760">
Libellé de l'élément</label>
</div>
<div class="form-check with-checked-bg">
<input checked="checked" class="form-check-input" id="checkbox-mixed_9408774761" name="form-checkbox_676265104" type="checkbox" value="checkbox-value_717822677">
<label class="form-check-label" for="checkbox-mixed_9408774761">
Libellé de l'élément</label>
</div>
<div class="form-check with-checked-bg">
<input class="form-check-input" id="checkbox-mixed_9408774762" name="form-checkbox_676265104" type="checkbox" value="checkbox-value_655977318">
<label class="form-check-label" for="checkbox-mixed_9408774762">
Libellé de l'élément</label>
</div>
<div class="form-check with-checked-bg">
<input class="form-check-input" id="checkbox-mixed_9408774763" name="form-checkbox_676265104" type="checkbox" value="checkbox-value_626826936">
<label class="form-check-label" for="checkbox-mixed_9408774763">
Libellé de l'élément</label>
</div>
</div>
</div>
// L'aperçu n'est pas disponible pour les dépendances externes
window.addEventListener('load', function () {
/**
* Désactivation du clic sur les input disabled
*/
// On liste les input disabled
const disabledInputs = document.querySelectorAll('[aria-disabled="true"]');
for (const input of disabledInputs) {
// Pour chaque input on empêche le click
input.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
});
// Pour chaque label associé, on empêche le click
const label = document.querySelector('[for="' + input.id + '"]');
if (label) {
document.querySelector('[for="' + input.id + '"]').addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
});
}
}
});
/* Mixed checkbox Script */
/*
* This content is licensed according to the W3C Software License at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document
*
* File: checkbox-mixed.js
*
* Desc: CheckboxMixed widget that implements ARIA Authoring Practices
* for a menu of links
* France Travail: Les commentaires ou modifications PE sont précédés d'un "PE:"
*/
'use strict';
class CheckboxMixed {
constructor(domNode) {
// PE: On cible la div checkbox "parent"
// (attention un vrai input checkbox n'est pas restitué sur Safari VoiceOver)
this.mixedNode = domNode.querySelector('.checkbox-mixed-controler');
// PE: On cible les checkbox "enfants"
this.checkboxNodes = domNode.querySelectorAll('.checkbox-group [type="checkbox"]');
this.mixedNode.addEventListener('keydown', this.onMixedKeydown.bind(this));
this.mixedNode.addEventListener('click', this.onMixedClick.bind(this));
this.mixedNode.addEventListener('focus', this.onMixedFocus.bind(this));
this.mixedNode.addEventListener('blur', this.onMixedBlur.bind(this));
for (var i = 0; i < this.checkboxNodes.length; i++) {
var checkboxNode = this.checkboxNodes[i];
checkboxNode.addEventListener('click', this.onCheckboxClick.bind(this));
checkboxNode.addEventListener('focus', this.onCheckboxFocus.bind(this));
checkboxNode.addEventListener('blur', this.onCheckboxBlur.bind(this));
checkboxNode.setAttribute('data-last-state', checkboxNode.checked);
}
this.updateMixed();
}
updateMixed() {
var count = 0;
for (var i = 0; i < this.checkboxNodes.length; i++) {
if (this.checkboxNodes[i].checked) {
count++;
}
}
if (count === 0) {
this.mixedNode.setAttribute('aria-checked', 'false');
} else {
if (count === this.checkboxNodes.length) {
this.mixedNode.setAttribute('aria-checked', 'true');
} else {
this.mixedNode.setAttribute('aria-checked', 'mixed');
this.updateCheckboxStates();
}
}
}
updateCheckboxStates() {
for (var i = 0; i < this.checkboxNodes.length; i++) {
var checkboxNode = this.checkboxNodes[i];
checkboxNode.setAttribute('data-last-state', checkboxNode.checked);
}
}
anyLastChecked() {
var count = 0;
for (var i = 0; i < this.checkboxNodes.length; i++) {
if (this.checkboxNodes[i].getAttribute('data-last-state') == 'true') {
count++;
}
}
return count > 0;
}
setCheckboxes(value) {
for (var i = 0; i < this.checkboxNodes.length; i++) {
var checkboxNode = this.checkboxNodes[i];
switch (value) {
case 'last':
checkboxNode.checked =
checkboxNode.getAttribute('data-last-state') === 'true';
break;
case 'true':
checkboxNode.checked = true;
break;
default:
checkboxNode.checked = false;
break;
}
}
this.updateMixed();
}
toggleMixed() {
var state = this.mixedNode.getAttribute('aria-checked');
if (state === 'false') {
if (this.anyLastChecked()) {
this.setCheckboxes('last');
} else {
this.setCheckboxes('true');
}
} else {
if (state === 'mixed') {
this.setCheckboxes('true');
} else {
this.setCheckboxes('false');
}
}
this.updateMixed();
}
/* EVENT HANDLERS */
onMixedKeydown(event) {
var flag = false;
switch (event.key) {
case ' ':
this.toggleMixed();
flag = true;
break;
default:
break;
}
if (flag) {
event.stopPropagation();
event.preventDefault();
}
}
onMixedClick() {
this.toggleMixed();
}
onMixedFocus() {
this.mixedNode.classList.add('focus');
}
onMixedBlur() {
this.mixedNode.classList.remove('focus');
}
onCheckboxClick(event) {
event.currentTarget.setAttribute(
'data-last-state',
event.currentTarget.checked
);
this.updateMixed();
}
onCheckboxFocus(event) {
event.currentTarget.parentNode.classList.add('focus');
}
onCheckboxBlur(event) {
event.currentTarget.parentNode.classList.remove('focus');
}
}
// Initialize mixed checkboxes on the page
window.addEventListener('load', function () {
for (const el of document.querySelectorAll('.checkbox-mixed')) {
new CheckboxMixed(el);
}
});