Backporting from concurrent project
This commit is contained in:
+18
-5
@@ -33,7 +33,9 @@ class Checkbox extends Toolkit.Component {
|
||||
this.add(this.uiLabel);
|
||||
|
||||
// Configure options
|
||||
this.checked = options.checked;
|
||||
this.checked = options.checked;
|
||||
this.disabled = !!options.disabled;
|
||||
this.instant = !!options.instant;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +67,12 @@ class Checkbox extends Toolkit.Component {
|
||||
|
||||
// Begin dragging
|
||||
this.element.setPointerCapture(e.pointerId);
|
||||
|
||||
// Use instant activation
|
||||
if (this.instant)
|
||||
return this.onPointerUp(e);
|
||||
|
||||
// Do not use instant activation
|
||||
this.element.classList.add("pushed");
|
||||
Toolkit.handle(e);
|
||||
}
|
||||
@@ -95,7 +103,7 @@ class Checkbox extends Toolkit.Component {
|
||||
|
||||
// Activate the check box if applicable
|
||||
if (this.isWithin(e))
|
||||
this.setChecked(!this.checked);
|
||||
this.setChecked(this.checked !== true);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,9 +111,12 @@ class Checkbox extends Toolkit.Component {
|
||||
///////////////////////////// Public Methods //////////////////////////////
|
||||
|
||||
// The check box is checked
|
||||
get checked() { return this.element.getAttribute("aria-checked")=="true"; }
|
||||
get checked() {
|
||||
let ret = this.element.getAttribute("aria-checked");
|
||||
return ret == "mixed" ? ret : ret == "true";
|
||||
}
|
||||
set checked(checked) {
|
||||
checked = !!checked;
|
||||
checked = checked == "mixed" ? checked : !!checked;
|
||||
if (checked == this.checked)
|
||||
return;
|
||||
this.element.setAttribute("aria-checked", checked);
|
||||
@@ -135,8 +146,10 @@ class Checkbox extends Toolkit.Component {
|
||||
checked = !!checked;
|
||||
if (checked == this.checked)
|
||||
return;
|
||||
let previous = this.checked
|
||||
this.checked = checked;
|
||||
this.element.dispatchEvent(new Event("input"));
|
||||
this.element.dispatchEvent(
|
||||
Object.assign(new Event("input"), { previous: previous }));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ class TextBox extends Toolkit.Component {
|
||||
onKeyDown(e) {
|
||||
if (e.altKey || e.ctrlKey || e.shiftKey || this.disabled)
|
||||
return;
|
||||
e.stopPropagation();
|
||||
if (e.key != "Tab")
|
||||
e.stopPropagation();
|
||||
if (e.key == "Enter")
|
||||
this.commit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user