docsearch icon indicating copy to clipboard operation
docsearch copied to clipboard

Invoke search overlay with a simple link

Open remcokalf opened this issue 2 years ago • 4 comments

I have the searchbox working on my pages.

Is it possible to also invoke the search overlay with a simple link in my body texts, without automatically creating the whole searchbox html at that position?

I don't see any options for the docsearch() function to use for that. Actually what command-K does, but working on a click instead of a keyboard event.

If this is not possible, I'd like to put this in as a feature request.

remcokalf avatar Dec 24 '21 16:12 remcokalf

Is it possible to also invoke the search overlay with a simple link in my body texts, without automatically creating the whole searchbox html at that position?

Sure, you can re-implement the DocSearch component on your side by providing your own DocSearchButton

shortcuts avatar Dec 26 '21 10:12 shortcuts

Ok, clear, however I am currently using docseach-js as simple as possible, without a package manager. I was hoping there would be an (undocumented) way to use docsearch() or another invoking function I can add to use a text link to open the overlay, without it creating the whole searchbox.

remcokalf avatar Dec 27 '21 11:12 remcokalf

Not pretty, but works:

<a href="javascript:document.getElementsByClassName('DocSearch-Button')[0].click()">Search</a>

wilhelmer avatar Jul 22 '22 06:07 wilhelmer

@wilhelmer thanks, that works nicely!

remcokalf avatar Jul 22 '22 10:07 remcokalf