Skip to content

Commit 88505d9

Browse files
committed
feat(checkbox): add unchecked value
resolves #69
1 parent c69c1ff commit 88505d9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/checkbox/ux-checkbox.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class UxCheckbox implements Themable {
2424
@bindable({ defaultBindingMode: bindingMode.twoWay })
2525
@bindable public value: any = null;
2626

27+
@bindable({ defaultBindingMode: bindingMode.twoWay })
28+
@bindable public uncheckedValue: any = null;
29+
2730
public view: View;
2831
private checkbox: Element;
2932
private ripple: PaperRipple | null = null;
@@ -54,13 +57,14 @@ export class UxCheckbox implements Themable {
5457

5558
public checkedChanged() {
5659
const elementValue = this.model ? this.model : this.value;
60+
5761
let isChecked = this.checked;
5862

5963
if (Array.isArray(this.checked)) {
6064
isChecked = this.checked.some(item => this.matcher(item, elementValue));
6165
}
6266

63-
if (isChecked) {
67+
if (isChecked && isChecked !== this.uncheckedValue) {
6468
this.element.classList.add('checked');
6569
this.element.setAttribute('aria-checked', 'true');
6670
} else {
@@ -87,8 +91,12 @@ export class UxCheckbox implements Themable {
8791

8892
this.checkedChanged();
8993
} else if (elementValue != null && typeof elementValue !== 'boolean') {
90-
if (this.checked) {
91-
this.checked = null;
94+
if (this.checked && this.checked !== this.uncheckedValue) {
95+
if (this.uncheckedValue != null) {
96+
this.checked = this.uncheckedValue;
97+
} else {
98+
this.checked = null;
99+
}
92100
} else {
93101
this.checked = elementValue;
94102
}

0 commit comments

Comments
 (0)