Focus search bar when open and allow opening it with [/]

This commit is contained in:
daudix
2024-10-02 03:41:21 +03:00
parent 8085b6355c
commit eae48b3762
2 changed files with 188 additions and 175 deletions

View File

@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased](https://codeberg.org/daudix/duckquill/compare/v5.3.2...main) ## [Unreleased](https://codeberg.org/daudix/duckquill/compare/v5.3.2...main)
### Changed
- Allow opening search by pressing the slash key.
- Focus search after opening it.
## [5.3.2](https://codeberg.org/daudix/duckquill/compare/v5.3.1...v5.3.2) ## [5.3.2](https://codeberg.org/daudix/duckquill/compare/v5.3.1...v5.3.2)
### Fixed ### Fixed

View File

@ -194,8 +194,16 @@
var searchBar = document.getElementById("search-bar"); var searchBar = document.getElementById("search-bar");
searchContainer.classList.toggle("active"); searchContainer.classList.toggle("active");
searchBar.toggleAttribute("disabled"); searchBar.toggleAttribute("disabled");
searchBar.focus();
} }
document.addEventListener("keydown", function(event) {
if (event.key === "/") {
event.preventDefault();
toggleSearch();
}
});
if (document.readyState === "complete" || if (document.readyState === "complete" ||
(document.readyState !== "loading" && !document.documentElement.doScroll) (document.readyState !== "loading" && !document.documentElement.doScroll)
) { ) {