algolia / docsearch

:blue_book: The easiest way to add search to your documentation.
https://docsearch.algolia.com
MIT License
3.92k stars 381 forks source link

Invoke search overlay with a simple link #1237

Open remcokalf opened 2 years ago

remcokalf commented 2 years ago

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.

shortcuts commented 2 years ago

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

remcokalf commented 2 years ago

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.

wilhelmer commented 2 years ago

Not pretty, but works:

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

@wilhelmer thanks, that works nicely!