From 14853f8173b360c22f69a7d5709384593bc03ca7 Mon Sep 17 00:00:00 2001 From: Eric Holscher <25510+ericholscher@users.noreply.github.com> Date: Thu, 19 Dec 2024 12:01:35 -0800 Subject: [PATCH] Support web components for globalKeyHandler Fixes https://github.com/rust-lang/mdBook/issues/2507 --- src/theme/searcher/searcher.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/theme/searcher/searcher.js b/src/theme/searcher/searcher.js index dc03e0a02d..1b2d59ead7 100644 --- a/src/theme/searcher/searcher.js +++ b/src/theme/searcher/searcher.js @@ -316,7 +316,9 @@ window.search = window.search || {}; // Eventhandler for keyevents on `document` function globalKeyHandler(e) { - if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.type === 'textarea' || e.target.type === 'text' || !hasFocus() && /^(?:input|select|textarea)$/i.test(e.target.nodeName)) { return; } + // Support web components along with normal HTML to get the proper target + target = e.composedPath()[0] + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || target.type === 'textarea' || target.type === 'text' || !hasFocus() && /^(?:input|select|textarea)$/i.test(target.nodeName)) { return; } if (e.keyCode === ESCAPE_KEYCODE) { e.preventDefault();