Skip to content

Commit

Permalink
Fix focus on input
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebelung-Dev committed Jan 28, 2024
1 parent 33a6980 commit 769bf67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,15 @@
- [x] Update settings layout
- [x] More languages

# Todo
- [ ] Suggestions with icon for website or search
- [ ] Clear search on enter
- [ ] Apps
- [ ] Games
- [ ] Discord and github
- [ ] Config file
- [ ] Privacy policy
- [ ] "Open" option in settings => search with: default, direct, about:blank

### Roadmap
The roadmap has moved [here](https://github.com/orgs/cognetwork-dev/projects/1/views/1).
12 changes: 10 additions & 2 deletions src/pages/home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "preact/hooks";
import { useState, useEffect, useRef } from "preact/hooks";
import { useGlobalState } from "@ekwoka/preact-global-state";
import { Head } from "../components/head";
import { Web, searchWeb } from "../components/web";
Expand All @@ -10,7 +10,14 @@ function Home() {
const [theme] = useGlobalState<string>("theme", localStorage.getItem("metallic/theme") || "default");
const [searchEngine] = useGlobalState<string>("engine", localStorage.getItem("metallic/engine") || "google");
const [webOpen, setWebOpen] = useState(false);
const search = useRef<HTMLInputElement>();

useEffect(() => {
if (search && search.current) {
search.current.focus();
}
}, [location.pathname])

const handleSearch = async (e: any) => {
if (e.key == "Enter") {
if (e.target.value) {
Expand All @@ -36,7 +43,8 @@ function Home() {
<div class="w-16 h-full flex items-center justify-center">
<SearchIcon />
</div>
<input autoFocus={true} onKeyUp={handleSearch} class="bg-transparent w-full h-full outline-none text-textInverse" spellcheck={false} autocomplete="off" data-enable-grammarly="false" />
{/**@ts-ignore */}
<input ref={search} autoFocus={true} onKeyUp={handleSearch} class="bg-transparent w-full h-full outline-none text-textInverse" spellcheck={false} autocomplete="off" data-enable-grammarly="false" />
</div>
</div>
</>
Expand Down

0 comments on commit 769bf67

Please sign in to comment.