File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ <h3>{{ _('Navigation') }}</h3>
4848 {%- if builder != "htmlhelp" %}
4949 < div class ="inline-search " role ="search ">
5050 < form class ="inline-search " action ="{{ pathto('search') }} " method ="get ">
51- < input placeholder ="{{ _('Quick search') }} " aria-label ="{{ _('Quick search') }} " type ="search " name ="q " />
51+ < input placeholder ="{{ _('Quick search') }} " aria-label ="{{ _('Quick search') }} " type ="search " name ="q " id =" search-box " />
5252 < input type ="submit " value ="{{ _('Go') }} " />
5353 </ form >
5454 </ div >
@@ -76,6 +76,7 @@ <h3>{{ _('Navigation') }}</h3>
7676 {%- if not embedded %}
7777 < script type ="text/javascript " src ="{{ pathto('_static/copybutton.js', 1) }} "> </ script >
7878 < script type ="text/javascript " src ="{{ pathto('_static/menu.js', 1) }} "> </ script >
79+ < script type ="text/javascript " src ="{{ pathto('_static/search-focus.js', 1) }} "> </ script >
7980 < script type ="text/javascript " src ="{{ pathto('_static/themetoggle.js', 1) }} "> </ script >
8081 {%- endif -%}
8182 {%- endif -%}
Original file line number Diff line number Diff line change 1+ function isInputFocused ( ) {
2+ const activeElement = document . activeElement ;
3+ return (
4+ activeElement . tagName === 'INPUT' ||
5+ activeElement . tagName === 'TEXTAREA' ||
6+ activeElement . isContentEditable
7+ ) ;
8+ }
9+
10+ document . addEventListener ( 'keydown' , function ( event ) {
11+ if ( event . key === '/' ) {
12+ if ( ! isInputFocused ( ) ) {
13+ // Prevent "/" from being entered in the search box
14+ event . preventDefault ( ) ;
15+
16+ // Set the focus on the search box
17+ const searchBox = document . getElementById ( 'search-box' ) ;
18+ searchBox . focus ( ) ;
19+ }
20+ }
21+ } ) ;
You can’t perform that action at this time.
0 commit comments