Skip to content

Commit

Permalink
fix: input focus on enter and popover instance
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Shandilya <[email protected]>
  • Loading branch information
void-hr committed Oct 16, 2024
1 parent 2188ab3 commit f8a2dcc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
18 changes: 4 additions & 14 deletions assets/js/offline-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
render($(event.target));

// Hide keyboard on mobile browser
$searchInput.blur();
// $searchInput.blur();
});

// Prevent reloading page by enter key on sidebar search.
Expand Down Expand Up @@ -62,23 +62,13 @@
// Dispose existing popover
//

{
let popover = bootstrap.Popover.getInstance($targetSearchInput[0]);
if (popover !== null) {
popover.dispose();
}
}
bootstrap.Popover.getInstance($targetSearchInput[0])?.dispose();

//
// Search
//

if (idx === null) {
return;
}

const searchQuery = $targetSearchInput.val();
if (searchQuery === '') {
if (idx === null || searchQuery === "") {
return;
}

Expand Down Expand Up @@ -182,7 +172,7 @@

//Bring focus to search bar
$(document).on('keydown', function (event) {
if (event.key === '/') {
if (event.key === '/' ) {
$searchInput.focus();
}
});
Expand Down
5 changes: 5 additions & 0 deletions layouts/partials/hotkey.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
href="https://unpkg.com/[email protected]/dist/css/main.min.css"
/>
<script>
function focusSearchBar (){
var searchBar = document.querySelector(".td-search__input");
searchBar.focus();
}

searchKey.addEventListener("click", () => {
event.preventDefault();
focusSearchBar();
Expand Down

0 comments on commit f8a2dcc

Please sign in to comment.