Skip to content

Commit 1b79929

Browse files
committed
feat: search focus.
1 parent 545a301 commit 1b79929

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/components/Navbar.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import { Link } from 'react-router-dom';
33
import Fez from './Fez';
4-
import { Sidebar, User, BookOpen, MagnifyingGlass } from '@phosphor-icons/react';
4+
import { SidebarIcon, UserIcon, BookOpenIcon, MagnifyingGlassIcon } from '@phosphor-icons/react';
55

66
const Navbar = ({ toggleSidebar, isSidebarOpen, toggleSearch }) => {
77
const [isScrolled, setIsScrolled] = useState(false);
@@ -24,15 +24,15 @@ const Navbar = ({ toggleSidebar, isSidebarOpen, toggleSearch }) => {
2424
onClick={toggleSidebar}
2525
className="absolute top-1/2 -translate-y-1/2 left-4 text-red-500 focus:outline-none hidden md:block"
2626
>
27-
<Sidebar size={24} />
27+
<SidebarIcon size={24} />
2828
</button>
2929
<div className="container mx-auto flex justify-between items-center p-4 text-white">
3030
<div className="md:hidden flex items-center space-x-2">
3131
<button
3232
onClick={toggleSidebar}
3333
className="text-white focus:outline-none"
3434
>
35-
<Sidebar size={24} />
35+
<SidebarIcon size={24} />
3636
</button>
3737
<Link to="/" className="flex items-center space-x-2">
3838
<Fez />
@@ -66,22 +66,22 @@ const Navbar = ({ toggleSidebar, isSidebarOpen, toggleSearch }) => {
6666
to="/about"
6767
className="flex items-center space-x-1 text-gray-300 hover:text-white hover:bg-gray-800 px-2 py-2 rounded-md transition-colors"
6868
>
69-
<User size={24} />
69+
<UserIcon size={24} />
7070
<span className="md:hidden lg:inline">About</span>
7171
</Link>
7272
<Link
7373
to="/blog"
7474
className="flex items-center space-x-1 text-gray-300 hover:text-white hover:bg-gray-800 px-2 py-2 rounded-md transition-colors"
7575
>
76-
<BookOpen size={24} />
76+
<BookOpenIcon size={24} />
7777
<span className="md:hidden lg:inline">Blog</span>
7878
</Link>
7979
<button
8080
onClick={toggleSearch}
8181
className="text-gray-300 hover:text-white hover:bg-gray-800 px-2 py-2 rounded-md transition-colors"
8282
aria-label="Toggle Search"
8383
>
84-
<MagnifyingGlass size={24} />
84+
<MagnifyingGlassIcon size={24} />
8585
</button>
8686
</div>
8787
</div>

src/components/Search.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,15 @@ const Search = ({ isVisible }) => {
66
const [searchTerm, setSearchTerm] = useState('');
77
const [searchResults, setSearchResults] = useState([]);
88
const [isDropdownOpen, setIsDropdownOpen] = useState(false);
9-
const [data, setData] = useState({ posts: [], projects: [], logs: [], routes: [], apps: [] }); // Add routes to data
9+
const [data, setData] = useState({ posts: [], projects: [], logs: [], routes: [], apps: [] });
1010
const searchRef = useRef(null);
11+
const inputRef = useRef(null);
12+
13+
useEffect(() => {
14+
if (isVisible && inputRef.current) {
15+
inputRef.current.focus();
16+
}
17+
}, [isVisible]);
1118

1219
useEffect(() => {
1320
const fetchData = async () => {
@@ -142,6 +149,7 @@ const Search = ({ isVisible }) => {
142149
<div ref={searchRef} className="w-full bg-gray-900 py-3 px-4 border-b border-gray-700">
143150
<form onSubmit={(e) => e.preventDefault()} className="relative w-full max-w-md mx-auto">
144151
<input
152+
ref={inputRef}
145153
type="text"
146154
placeholder="Search..."
147155
value={searchTerm}

0 commit comments

Comments
 (0)