Skip to content

Commit 715efc8

Browse files
committed
fix: do not focus on buttons that are hidden via CSS
1 parent baa5138 commit 715efc8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ const buttonSelectors = [
1818
function getButtons(toolbar: Element): Element[] {
1919
const els = []
2020
for (const button of toolbar.querySelectorAll(buttonSelectors.join(', '))) {
21-
if (button.closest('markdown-toolbar') === toolbar && !button.hidden) els.push(button)
21+
// Skip buttons that are hidden, either via `hidden` attribute or CSS:
22+
if (button.hidden || (button.offsetWidth <= 0 && button.offsetHeight <= 0)) continue
23+
if (button.closest('markdown-toolbar') === toolbar) els.push(button)
2224
}
2325
return els
2426
}

test/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ describe('markdown-toolbar-element', function() {
7171
<md-bold>bold</md-bold>
7272
<md-header>header</md-header>
7373
<md-header level="1">h1</md-header>
74-
<md-header level="5" hidden>h1</md-header>
74+
<div hidden>
75+
<md-header level="5">h1</md-header>
76+
</div>
7577
<md-header level="10">h1</md-header>
7678
<div data-md-button>Other button</div>
7779
<md-italic>italic</md-italic>

0 commit comments

Comments
 (0)