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

Add keyboard shortcut to focus search field #31702

Merged
merged 6 commits into from Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions site/assets/js/search.js
Expand Up @@ -12,6 +12,13 @@
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
Expand Down
33 changes: 30 additions & 3 deletions site/assets/scss/_subnav.scss
Expand Up @@ -25,9 +25,36 @@
}

.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);
}
}
}

Expand Down