Skip to content

Commit

Permalink
vdoc: select first result when entering search term, use more explict…
Browse files Browse the repository at this point in the history
… query for `header.doc-nav` (#21193)
  • Loading branch information
ttytm authored Apr 6, 2024
1 parent 3a6cf5a commit 3d5dbca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/tools/vdoc/theme/doc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function () {
const docnav = document.querySelector('.doc-nav');
const docnav = document.querySelector('header.doc-nav');
const active = docnav.querySelector('li.active');
active?.scrollIntoView({ block: 'center', inline: 'nearest' });
setupMobileToggle();
Expand Down Expand Up @@ -62,7 +62,7 @@ function setupScrollSpy() {

function setupMobileToggle() {
document.getElementById('toggle-menu').addEventListener('click', () => {
const docNav = document.querySelector('.doc-nav');
const docNav = document.querySelector('header.doc-nav');
const isHidden = docNav.classList.contains('hidden');
docNav.classList.toggle('hidden');
const search = docNav.querySelector('.search');
Expand Down Expand Up @@ -92,7 +92,7 @@ function setupDarkMode() {
function setupSearch() {
const onInputChange = debounce((e) => {
const searchValue = e.target.value.toLowerCase();
const docNav = document.querySelector('.doc-nav');
const docNav = document.querySelector('header.doc-nav');
const menu = docNav.querySelector('.content');
const search = docNav.querySelector('.search');
if (searchValue === '') {
Expand Down Expand Up @@ -182,6 +182,7 @@ function setupSearch() {
function setupSearchKeymaps() {
const searchInput = document.querySelector('#search input');
const mainContent = document.querySelector('#main-content');
const docnav = document.querySelector('header.doc-nav');
// Keyboard shortcut indicator
const searchKeys = document.createElement('div');
const modifierKeyPrefix = navigator.platform.includes('Mac') ? '⌘' : 'Ctrl';
Expand Down Expand Up @@ -241,6 +242,7 @@ function setupSearchKeymaps() {
}
break;
default:
docnav.scroll(0, 0);
selectedIdx = -1;
}
});
Expand Down

0 comments on commit 3d5dbca

Please sign in to comment.