Skip to content

Commit 79fa532

Browse files
committed
feat(change event): add and expose
Also includes fix for setting the value for all types.
1 parent 3dd0db6 commit 79fa532

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/client/scripts/rb-checkbox.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export class RbCheckbox extends FormControl(RbBase()) {
6767
return code.toLowerCase();
6868
}
6969
async setValue(value) { // :void
70-
if (this.value === undefined || this.state.value === undefined) return this.value = true;
70+
if (typeof(value) !== 'boolean' && value !== undefined) return this.value = null;
7171
if (typeof(value) === 'boolean') return this.value = !value;
72-
if (!!this.value) return this.value = null;
72+
if (props.value === undefined && this.state.value === undefined) return this.value = !this.value;
7373
this.value = this.state.value;
7474
}
7575

@@ -90,9 +90,14 @@ export class RbCheckbox extends FormControl(RbBase()) {
9090

9191
/* Event Handlers
9292
*****************/
93+
_onchange(evt) { // :void
94+
this.rb.events.emit(this, 'change', {
95+
detail: { value: this.value }
96+
});
97+
}
9398
async _onclick(value, evt) { // :void
9499
this.setValue(value);
95-
await this.validate()
100+
await this.validate();
96101
}
97102
async _onkeypress(value, evt) { // :void
98103
const keys = ['enter','space'];
@@ -102,6 +107,7 @@ export class RbCheckbox extends FormControl(RbBase()) {
102107
this.setValue(value);
103108
await this.validate()
104109
this.rb.elms.formControl.checked = this.value; // needed for firefox
110+
this._onchange(evt);
105111
}
106112

107113
/* Template

src/client/styles/main/host.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* HOST
33
*******/
44
:host {
5-
contain: content;
5+
contain: layout style; // paint causes hover circle to cut off in checkboxes
66
}
77
:host([hidden]) {
88
display: none;

src/client/views/rb-checkbox.html

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
name="${props.name}"
2525
.value="${props.value}"
2626
?checked="${!!props.value}"
27+
@change="${this._onchange.bind(this)}"
2728
@click="${this._onclick.bind(this, props.value)}">
2829
<b class="checkbox"></b>
2930
${props.sublabel}

0 commit comments

Comments
 (0)