mdBook icon indicating copy to clipboard operation
mdBook copied to clipboard

Avoid triggering search when `s` is pressed on active input.

Open ericholscher opened this issue 11 months ago • 2 comments

Problem

We're trying to add a custom search element to mdbook docs, and the default search logic keeps stealing the s key when we try to type it into the search box of our alternate search.

Steps

  1. To go https://test-builds.readthedocs.io/en/mdbook/
  2. Press / to bring up our custom search
  3. Try to type a word with s in it.

Possible Solution(s)

The mdbook search logic should not fire when there is an input element that has focus.

It seems like https://github.com/rust-lang/mdBook/blob/master/src/theme/searcher/searcher.js#L319 should be checking for input types as well as textarea types?

Notes

No response

Version

mdbook v0.4.43

ericholscher avatar Dec 17 '24 17:12 ericholscher

It should already be checking for input via the check on e.target.nodeName. Maybe attach a debugger and see why that isn't included?

ehuss avatar Dec 18 '24 00:12 ehuss

@ehuss Thanks for the note. It looks like this happens because of a web component:

Image

I think that using e.composedPath()[0]​ would likely catch this use case, if it's something you wanted to support it.

ericholscher avatar Dec 18 '24 21:12 ericholscher