Skip to content

Commit fbe35e9

Browse files
author
Ryan A. Johnson
committed
feat(HXTooltip): emit open/close events
1 parent 97e5059 commit fbe35e9

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

docs/elements/hx-tooltip/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
<hx-dt>Permitted Children</hx-dt>
2121
<hx-dd>flow content</hx-dd>
2222
</hx-def>
23+
<hx-def>
24+
<hx-dt>Events</hx-dt>
25+
<hx-dd>
26+
Any of the following:
27+
<ul>
28+
<li><code>close</code></li>
29+
<li><code>open</code></li>
30+
</ul>
31+
</hx-dd>
32+
</hx-def>
2333
</hx-dl>
2434
</section>
2535
{% endblock %}

src/helix-ui/elements/HXTooltipElement.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export class HXTooltipElement extends HXElement {
3636
this.$upgradeProperty('open');
3737
this.$defaultAttribute('role', 'tooltip');
3838

39+
this.setAttribute('aria-hidden', !this.open);
40+
3941
if (this.id) {
4042
this._target = this.getRootNode().querySelector('[data-tooltip=' + this.id + ']');
4143
} else {
@@ -51,8 +53,13 @@ export class HXTooltipElement extends HXElement {
5153
this._destoryAllHandlers();
5254
}
5355

54-
attributeChangedCallback (attr, oldValue, newValue) {
55-
this.setAttribute('aria-hidden', newValue !== '');
56+
attributeChangedCallback (attr, oldVal, newVal) {
57+
let isOpen = (newVal !== null);
58+
this.setAttribute('aria-hidden', !isOpen);
59+
60+
if (newVal !== oldVal) {
61+
this.$emit(isOpen ? 'open' : 'close');
62+
}
5663
}
5764

5865
_hide () {

0 commit comments

Comments
 (0)