Skip to content

Commit

Permalink
Merge pull request #206 from uselagoon/searchbar-focus
Browse files Browse the repository at this point in the history
  • Loading branch information
tobybellwood authored Dec 12, 2023
2 parents 0d321bb + a37e06e commit 8cff175
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/components/Projects/index.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 = '';
Expand All @@ -38,6 +45,7 @@ const Projects = ({ projects = [], initialSearch }) => {
</label>
<label></label>
<SearchInput
ref={searchInputRef}
aria-labelledby="search"
className="searchInput"
type="text"
Expand Down

0 comments on commit 8cff175

Please sign in to comment.