Skip to content

Commit 1cd0831

Browse files
authored
Clear search button (#419)
* Added clear button to News search input * Added clear button to News search input
1 parent c2cc19e commit 1cd0831

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/pages/News/NewsPage.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
Sparkles,
2424
Tag,
2525
Info,
26+
X,
2627
} from 'lucide-react';
2728

2829
const NewsPage: React.FC = () => {
@@ -303,8 +304,24 @@ const NewsPage: React.FC = () => {
303304
: '';
304305
navigate(`/news/${catPath}${query}`, { replace: true });
305306
}}
306-
className="w-full pl-10 pr-4 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
307+
className="w-full pl-10 pr-10 py-3 border border-gray-200 rounded-xl focus:ring-2 focus:ring-blue-500 focus:border-transparent transition-all duration-300"
307308
/>
309+
{searchTerm && (
310+
<button
311+
onClick={() => {
312+
setSearchTerm('');
313+
const catPath =
314+
activeCategory === 'All'
315+
? 'all'
316+
: activeCategory.toLowerCase().replace(/\s+/g, '-');
317+
navigate(`/news/${catPath}`, { replace: true });
318+
}}
319+
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
320+
aria-label="Clear search"
321+
>
322+
<X size={20} />
323+
</button>
324+
)}
308325
</div>
309326
</div>
310327

0 commit comments

Comments
 (0)