File tree Expand file tree Collapse file tree
gcp/website/frontend3/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,9 +58,27 @@ export class ExpandableSearch {
5858 handleDocumentKeydown ( e ) {
5959 if ( e . key === 'Escape' && this . isSearchActive ( ) ) {
6060 this . closeSearch ( ) ;
61+ return ;
62+ }
63+
64+ // Press "/" to jump to the search box, unless already typing in a field.
65+ if ( e . key === '/' && ! e . ctrlKey && ! e . metaKey && ! e . altKey &&
66+ ! this . isTypingContext ( e . target ) ) {
67+ e . preventDefault ( ) ;
68+ this . openSearch ( ) ;
6169 }
6270 }
6371
72+ isTypingContext ( target ) {
73+ if ( ! target ) return false ;
74+ if ( target . isContentEditable ) return true ;
75+ // Native form fields, and Material web text fields whose focus retargets to
76+ // the custom element host (e.g. md-filled-text-field, md-textfield-with-*).
77+ const tag = target . tagName ? target . tagName . toLowerCase ( ) : '' ;
78+ return tag === 'input' || tag === 'textarea' || tag === 'select' ||
79+ tag . includes ( 'textfield' ) || tag . includes ( 'text-field' ) ;
80+ }
81+
6482 initializeSearch ( ) {
6583 const searchContainer = document . querySelector ( '.search-container-nav' ) ;
6684 if ( ! searchContainer ) {
You can’t perform that action at this time.
0 commit comments