Skip to content

Commit b7824fb

Browse files
committed
fix: input focus on enter and popover instance
1 parent 2188ab3 commit b7824fb

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

Diff for: assets/js/offline-search.js

+4-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
render($(event.target));
1515

1616
// Hide keyboard on mobile browser
17-
$searchInput.blur();
17+
// $searchInput.blur();
1818
});
1919

2020
// Prevent reloading page by enter key on sidebar search.
@@ -62,23 +62,13 @@
6262
// Dispose existing popover
6363
//
6464

65-
{
66-
let popover = bootstrap.Popover.getInstance($targetSearchInput[0]);
67-
if (popover !== null) {
68-
popover.dispose();
69-
}
70-
}
65+
bootstrap.Popover.getInstance($targetSearchInput[0])?.dispose();
7166

7267
//
7368
// Search
7469
//
75-
76-
if (idx === null) {
77-
return;
78-
}
79-
8070
const searchQuery = $targetSearchInput.val();
81-
if (searchQuery === '') {
71+
if (idx === null || searchQuery === "") {
8272
return;
8373
}
8474

@@ -182,7 +172,7 @@
182172

183173
//Bring focus to search bar
184174
$(document).on('keydown', function (event) {
185-
if (event.key === '/') {
175+
if (event.key === '/' ) {
186176
$searchInput.focus();
187177
}
188178
});

Diff for: layouts/partials/hotkey.html

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
href="https://unpkg.com/[email protected]/dist/css/main.min.css"
1414
/>
1515
<script>
16+
function focusSearchBar (){
17+
var searchBar = document.querySelector(".td-search__input");
18+
searchBar.focus();
19+
}
20+
1621
searchKey.addEventListener("click", () => {
1722
event.preventDefault();
1823
focusSearchBar();

0 commit comments

Comments
 (0)