From a37e06e8e1c3d98516cc84c3b9594b91dc0f7485 Mon Sep 17 00:00:00 2001 From: Davit Date: Tue, 12 Dec 2023 13:24:47 +0400 Subject: [PATCH] focus searchbar if someone was typing as page was loading --- src/components/Projects/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/Projects/index.js b/src/components/Projects/index.js index af804438..16668755 100644 --- a/src/components/Projects/index.js +++ b/src/components/Projects/index.js @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import Highlighter from 'react-highlight-words'; import Box from 'components/Box'; @@ -19,6 +19,13 @@ import { const Projects = ({ projects = [], initialSearch }) => { const [searchInput, setSearchInput] = useState(initialSearch); + const searchInputRef = useRef(null); + + useEffect(() => { + if (initialSearch && searchInputRef.current) { + searchInputRef.current.focus(); + } + }, []); const filteredProjects = projects.filter(key => { const sortByName = key.name.toLowerCase().includes(searchInput.trim().toLowerCase()); let sortByUrl = ''; @@ -38,6 +45,7 @@ const Projects = ({ projects = [], initialSearch }) => {