From e5535adf6efed7688e4929631d93e796f71a5198 Mon Sep 17 00:00:00 2001 From: Emre Yilmaz Date: Thu, 16 May 2024 00:55:22 +0300 Subject: [PATCH] Fix check all behavior with disabled inputs Issue: #21 --- src/index.ts | 2 +- test/test.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 7f9746b..bcf40ff 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,7 +10,7 @@ export default function subscribe(container: HTMLElement): Subscription { container.addEventListener('change', onChange) function setChecked(target: Element, input: HTMLElement, checked: boolean, indeterminate = false): void { - if (!(input instanceof HTMLInputElement)) return + if (!(input instanceof HTMLInputElement) || input.disabled) return input.indeterminate = indeterminate if (input.checked !== checked) { diff --git a/test/test.js b/test/test.js index 4bbd9cf..40432f7 100644 --- a/test/test.js +++ b/test/test.js @@ -78,4 +78,17 @@ describe('check-all', function () { assert(checkboxes[3].checked) assert(checkAll.indeterminate) }) + + it('checks all without disabled', function () { + const checkAll = document.querySelector('[data-check-all]') + const count = document.querySelector('[data-check-all-count]') + const checkboxes = document.querySelectorAll('[data-check-all-item]') + checkboxes[1].disabled = true + checkboxes[2].disabled = true + checkboxes[3].disabled = true + checkAll.click() + assert.equal(count.textContent, '1') + assert.equal(document.querySelectorAll('[data-check-all-item]:checked').length, 1) + assert.notOk(checkAll.indeterminate) + }) })