Skip to content

Commit 0b8c431

Browse files
author
Ryan A. Johnson
committed
feat(HXCheckboxElement): add declarative functionality
* Add `click()` to simulate mouse click * Refactor source to use `$` API from HXElement (fixes aria behavior) * Update visreg snapshots with corrected behavior
1 parent bdaad83 commit 0b8c431

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

docs/elements/hx-checkbox/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
</hx-def>
2828
</hx-dl>
2929
</section>
30+
31+
<section>
32+
<h2 id="methods">Methods</h2>
33+
<dl>
34+
<dt>click()</dt>
35+
<dd>Simulates a mouse click on the element</dd>
36+
</dl>
37+
</section>
3038
{% endblock %}
3139

3240
{% block attributes %}

src/helix-ui/elements/HXCheckboxElement.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export class HXCheckboxElement extends HXElement {
3535
this.$upgradeProperty('checked');
3636
this.$upgradeProperty('disabled');
3737
this.$upgradeProperty('indeterminate');
38-
this._input.addEventListener('change', this._onChange);
38+
this._chkInput.addEventListener('change', this._onChange);
3939
}
4040

4141
$onDisconnect () {
42-
this._input.removeEventListener('change', this._onChange);
42+
this._chkInput.removeEventListener('change', this._onChange);
4343
}
4444

4545
static get $observedAttributes () {
@@ -54,15 +54,15 @@ export class HXCheckboxElement extends HXElement {
5454
const hasValue = (newVal !== null);
5555
switch (attr) {
5656
case 'indeterminate':
57-
this._input.indeterminate = hasValue;
57+
this._chkInput.indeterminate = hasValue;
5858
break;
5959
case 'checked':
60-
if (this._input.checked !== hasValue) {
61-
this._input.checked = hasValue;
60+
if (this._chkInput.checked !== hasValue) {
61+
this._chkInput.checked = hasValue;
6262
}
6363
break;
6464
case 'disabled':
65-
this._input.disabled = hasValue;
65+
this._chkInput.disabled = hasValue;
6666
break;
6767
}
6868
}
@@ -99,6 +99,13 @@ export class HXCheckboxElement extends HXElement {
9999
}
100100
}
101101

102+
/**
103+
* Pass-through function to native input.
104+
*/
105+
click () {
106+
this._chkInput.click();
107+
}
108+
102109
/** @private */
103110
_onChange (evt) {
104111
// Update internal state
@@ -112,7 +119,7 @@ export class HXCheckboxElement extends HXElement {
112119
}
113120

114121
/** @private */
115-
get _input () {
122+
get _chkInput () {
116123
return this.shadowRoot.getElementById('hxNativeControl');
117124
}
118125
}

0 commit comments

Comments
 (0)