Skip to content

Commit 20c5311

Browse files
author
Ryan A. Johnson
committed
feat(HXPopover): emit open/close events
1 parent 1a72e15 commit 20c5311

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/elements/hx-popover/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
</ol>
3131
</hx-dd>
3232
</hx-def>
33+
<hx-def>
34+
<hx-dt>Events</hx-dt>
35+
<hx-dd>
36+
Any of the following:
37+
<ul>
38+
<li><code>close</code></li>
39+
<li><code>open</code></li>
40+
</ul>
41+
</hx-dd>
42+
</hx-def>
3343
</hx-dl>
3444
</section>
3545
{% endblock %}

src/helix-ui/elements/HXPopoverElement.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export class HXPopoverElement extends HXElement {
3737
this.$defaultAttribute('position', 'bottom-right');
3838
this._initialPosition = this.position;
3939

40+
this.setAttribute('aria-hidden', !this.open);
41+
4042
if (!this.id) {
4143
return;
4244
}
@@ -61,8 +63,13 @@ export class HXPopoverElement extends HXElement {
6163
document.removeEventListener('click', this._closeOnBackdropClick);
6264
}
6365

64-
attributeChangedCallback (attr, oldValue, newValue) {
65-
this.setAttribute('aria-hidden', newValue !== '');
66+
attributeChangedCallback (attr, oldVal, newVal) {
67+
let isOpen = (newVal !== null);
68+
this.setAttribute('aria-hidden', !isOpen);
69+
70+
if (newVal !== oldVal) {
71+
this.$emit(isOpen ? 'open' : 'close');
72+
}
6673
}
6774

6875
_toggle () {

0 commit comments

Comments
 (0)