Skip to content

Commit

Permalink
feat: logic between label checkbox and functional checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Pajung authored and nowseemee committed Jul 19, 2021
1 parent 0d77ccc commit f6669b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,39 @@ export class CheckboxGroup {
const checkboxes = Array.from(
this.hostElement.shadowRoot.querySelectorAll('scale-checkbox')
);
const labelBox = checkboxes[0];
const checked = event.detail.checked;
let countChecked = 0;
let countUnchecked = 0;
if (event.detail.id === 'checkbox1') {
labelBox.removeAttribute('indeterminate');
checkboxes.forEach((checkbox) => {
checkbox.checked = checked;
});
} else {
for (let i = 1; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
countChecked = countChecked + 1;
} else {
countUnchecked = countUnchecked + 1;
}
return;
}

for (let i = 1; i < checkboxes.length; i++) {
if (checkboxes[i].checked) {
countChecked += 1;
} else {
countUnchecked += 1;
}
}

if (countChecked === checkboxes.length - 1) {
checkboxes[0].checked = true;
labelBox.removeAttribute('indeterminate');
labelBox.checked = true;
return;
}
if (countUnchecked === checkboxes.length - 1) {
checkboxes[0].checked = false;
labelBox.removeAttribute('indeterminate');
labelBox.checked = false;
return;
}
console.log('indeterminated state');
labelBox.setAttribute('indeterminate', 'true');
labelBox.removeAttribute('checked');
}

render() {
Expand Down Expand Up @@ -101,9 +109,6 @@ export class CheckboxGroup {
</div>
</div>
</div>
{/* <button class="button" onClick={this.setCheckboxes}>
click
</button>*/}
</Host>
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/components/checkbox/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class Checkbox {
<div class="checkbox__control-wrapper">
<span class="checkbox__control"></span>
{/* Accessibility: rendering the icon *only* when checked, otherwise is always visible in HCM */}
{this.checked && !this.indeterminate && (
{this.checked && (
<scale-icon-action-success
class="icon"
decorative
Expand Down

0 comments on commit f6669b9

Please sign in to comment.