Skip to content

Commit

Permalink
Merge pull request #50 from ymzEmre/main
Browse files Browse the repository at this point in the history
Fix check all behavior with disabled inputs #21
  • Loading branch information
keithamus authored May 16, 2024
2 parents 02306fe + e5535ad commit cee129b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit cee129b

Please sign in to comment.