Skip to content

Commit b88695f

Browse files
committed
fix(tooltip): ESC key closes tooltip #138
1 parent a651b1a commit b88695f

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

_disclosure/tooltip/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ <h2>Example 4: Interactive Content (discouraged)</h2>
5050

5151
<hr />
5252

53-
<p><i>Updated</i>: May 12th, 2019</p>
53+
<p><i>Updated</i>: Jul 9th, 2025</p>

_js/tooltip.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@ const defaultOptions = {
1313
hostSelector: '.tooltip__host, [aria-describedby]'
1414
};
1515

16+
function onDocumentKeyDown() {
17+
this.expander.expanded = false;
18+
}
19+
1620
export default class {
1721
constructor(widgetEl, selectedOptions) {
1822
this._options = Object.assign({}, defaultOptions, selectedOptions);
1923

2024
this._el = widgetEl;
2125

26+
this._onDocumentKeyDownListener = onDocumentKeyDown.bind(this);
27+
2228
this.expander = new Expander(widgetEl, {
2329
autoCollapse: true,
2430
contentSelector: this._options.contentSelector,
@@ -35,6 +41,7 @@ export default class {
3541
}
3642

3743
sleep() {
44+
document.removeEventListener('keydown', this._onDocumentKeyDownListener);
3845
this.expander.expandOnFocus = false;
3946
this.expander.expandOnHover = false;
4047
}
@@ -43,11 +50,13 @@ export default class {
4350
if (this._destroyed !== true) {
4451
this.expander.expandOnFocus = true;
4552
this.expander.expandOnHover = true;
53+
document.addEventListener('keydown', this._onDocumentKeyDownListener);
4654
}
4755
}
4856

4957
destroy() {
5058
this._destroyed = true;
5159
this.sleep();
60+
this._onDocumentKeyDownListener = null;
5261
}
5362
}

static/browser.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/browser.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)