Files
msgapp/src/app/components/SearchBar.tsx
mota 9d7cdf238a feat(ui): 검색 UX 개선(aria, clear 버튼, enterKeyHint)
docs(todo): 헤더 네비 6번 완료 표시
2025-10-13 08:16:47 +09:00

41 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useRouter } from "next/navigation";
import { useState } from "react";
export function SearchBar() {
const router = useRouter();
const [term, setTerm] = useState("");
return (
<form
onSubmit={(e) => {
e.preventDefault();
const q = term.trim();
router.push(q ? `/search?q=${encodeURIComponent(q)}` : "/search");
}}
role="search"
aria-label="사이트 검색"
style={{ display: "flex", gap: 8, alignItems: "center" }}
>
<input
type="search"
name="q"
value={term}
onChange={(e) => setTerm(e.target.value)}
placeholder="검색어 입력"
enterKeyHint="search"
aria-label="검색어"
onKeyDown={(e) => {
if (e.key === "Escape") setTerm("");
}}
style={{ padding: "6px 8px", border: "1px solid #ddd", borderRadius: 6, minWidth: 160 }}
/>
{term && (
<button type="button" aria-label="검색어 지우기" onClick={() => setTerm("")}>×</button>
)}
<button type="submit"></button>
</form>
);
}