]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Add keyboard shortcut to focus search field (#31702)
authorMark Otto <markd.otto@gmail.com>
Thu, 5 Nov 2020 16:56:02 +0000 (08:56 -0800)
committerGitHub <noreply@github.com>
Thu, 5 Nov 2020 16:56:02 +0000 (08:56 -0800)
* Documentation: Add slash key event to focus the input search.

* Add little tag for keyboard shortcut in the search field

* Use ctrl / as keyboard shortcut

* Update search.js

Co-authored-by: chuckrincon <chuckrincon@gmail.com>
Co-authored-by: Patrick H. Lauke <redux@splintered.co.uk>
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
site/assets/js/search.js
site/assets/scss/_subnav.scss

index bb97c5cf80c1504c9543e1722aa0cf5d0e80dd18..823dcb10a76e358df20b57a80cb475e6f2912858 100644 (file)
   var inputElement = document.getElementById('search-input')
   var siteDocsVersion = inputElement.getAttribute('data-docs-version')
 
+  document.addEventListener('keydown', function (event) {
+    if (event.ctrlKey && event.key === '/') {
+      event.preventDefault()
+      inputElement.focus()
+    }
+  })
+
   function getOrigin() {
     var location = window.location
     var origin = location.origin
index 566bc17fdc27e6f1fdbc7f458d6c81e12d82b3b4..c23d96a49b26bdebb0ae3c4165d784aaafe39553 100644 (file)
 }
 
 .bd-search {
-  .form-control:focus {
-    border-color: $bd-purple-bright;
-    box-shadow: 0 0 0 3px rgba($bd-purple-bright, .25);
+  position: relative;
+
+  &::after {
+    position: absolute;
+    top: .4rem;
+    right: .4rem;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+    height: 1.5rem;
+    padding-right: .25rem;
+    padding-left: .25rem;
+    @include font-size(.75rem);
+    color: $gray-600;
+    content: "Ctrl + /";
+    border: $border-width solid $border-color;
+    @include border-radius(.125rem);
+  }
+
+  @include media-breakpoint-down(md) {
+    width: 100%;
+  }
+
+  .form-control {
+    padding-right: 3.75rem;
+
+    &:focus {
+      border-color: $bd-purple-bright;
+      box-shadow: 0 0 0 3px rgba($bd-purple-bright, .25);
+    }
   }
 }