Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus search box when pressing slash #131

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion python_docs_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h3>{{ _('Navigation') }}</h3>
{%- if builder != "htmlhelp" %}
<div class="inline-search" role="search">
<form class="inline-search" action="{{ pathto('search') }}" method="get">
<input placeholder="{{ _('Quick search') }}" aria-label="{{ _('Quick search') }}" type="search" name="q" />
<input placeholder="{{ _('Quick search') }}" aria-label="{{ _('Quick search') }}" type="search" name="q" id="search-box" />
<input type="submit" value="{{ _('Go') }}" />
</form>
</div>
Expand Down Expand Up @@ -76,6 +76,7 @@ <h3>{{ _('Navigation') }}</h3>
{%- if not embedded %}
<script type="text/javascript" src="{{ pathto('_static/copybutton.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/menu.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/search-focus.js', 1) }}"></script>
<script type="text/javascript" src="{{ pathto('_static/themetoggle.js', 1) }}"></script>
{%- endif -%}
{%- endif -%}
Expand Down
10 changes: 10 additions & 0 deletions python_docs_theme/static/search-focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
document.addEventListener('keydown', function(event) {
if (event.key === '/') {
hugovk marked this conversation as resolved.
Show resolved Hide resolved
// Prevent "/" from being entered in the search box
event.preventDefault();

// Set the focus on the search box
let searchBox = document.getElementById('search-box');
searchBox.focus();
}
});