Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix check all behavior with disabled inputs #21 #50

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
})
})