Skip to content

Commit 39cf0ed

Browse files
mikebarkminCopilot
andcommitted
fix: protect directive not revealing when wrapping tabs
The protect client.js used getElementsByTagName('input')[0] to find the password input, which grabbed the first input in the entire subtree. When protect wrapped tabs, this selected a tab radio input instead of the password input, so event listeners were attached to the wrong element and password entry was silently ignored. Scope both selectors to direct children using :scope queries: - Input: el.querySelector(':scope > .password-input input') - Hidden: el.querySelector(':scope > .hidden') Co-authored-by: Copilot <[email protected]>
1 parent 841cf31 commit 39cf0ed

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperbook/markdown": patch
3+
---
4+
5+
Fix protect directive not revealing content when wrapping tabs or other directives containing input elements. The password input selector now scopes to the direct child `.password-input` container instead of selecting the first input in the entire subtree.

packages/markdown/assets/directive-protect/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ hyperbook.protect = (function () {
5454
function init(root) {
5555
const els = root.getElementsByClassName("directive-protect");
5656
for (let el of els) {
57-
const inputEl = el.getElementsByTagName("input")[0];
57+
const inputEl = el.querySelector(":scope > .password-input input");
5858
const id = el.getAttribute("data-id");
5959

6060
if (!inputEl) continue;
@@ -66,7 +66,7 @@ hyperbook.protect = (function () {
6666
}
6767
});
6868

69-
const hiddenEL = el.getElementsByClassName("hidden")[0];
69+
const hiddenEL = el.querySelector(":scope > .hidden");
7070
el.removeChild(hiddenEL);
7171

7272
onUpdateToast(inputEl, el, hiddenEL);

website/en/book/changelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ If you need a new feature, open an [issue](https://github.com/openpatch/hyperboo
3838
::::
3939
-->
4040

41+
## v0.89.2
42+
43+
::::tabs
44+
45+
:::tab{title="Fixed :bug:" id="fixed"}
46+
47+
- Fix protect directive not revealing content when wrapping tabs or other directives containing input elements.
48+
49+
:::
50+
51+
::::
52+
4153
## v0.89.1
4254

4355
::::tabs

0 commit comments

Comments
 (0)