Skip to content

Commit cee129b

Browse files
authored
Merge pull request #50 from ymzEmre/main
Fix check all behavior with disabled inputs #21
2 parents 02306fe + e5535ad commit cee129b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function subscribe(container: HTMLElement): Subscription {
1010
container.addEventListener('change', onChange)
1111

1212
function setChecked(target: Element, input: HTMLElement, checked: boolean, indeterminate = false): void {
13-
if (!(input instanceof HTMLInputElement)) return
13+
if (!(input instanceof HTMLInputElement) || input.disabled) return
1414

1515
input.indeterminate = indeterminate
1616
if (input.checked !== checked) {

test/test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,17 @@ describe('check-all', function () {
7878
assert(checkboxes[3].checked)
7979
assert(checkAll.indeterminate)
8080
})
81+
82+
it('checks all without disabled', function () {
83+
const checkAll = document.querySelector('[data-check-all]')
84+
const count = document.querySelector('[data-check-all-count]')
85+
const checkboxes = document.querySelectorAll('[data-check-all-item]')
86+
checkboxes[1].disabled = true
87+
checkboxes[2].disabled = true
88+
checkboxes[3].disabled = true
89+
checkAll.click()
90+
assert.equal(count.textContent, '1')
91+
assert.equal(document.querySelectorAll('[data-check-all-item]:checked').length, 1)
92+
assert.notOk(checkAll.indeterminate)
93+
})
8194
})

0 commit comments

Comments
 (0)