Skip to content

Commit

Permalink
Merge pull request #8017 from newrelic/clang/fix-home-search-icon-click
Browse files Browse the repository at this point in the history
[Home:Search] Fix undefined value when clicking on search icon
  • Loading branch information
roadlittledawn committed Jun 13, 2022
2 parents 076e1d7 + 63a3845 commit 60c1ba4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/pages/index.js
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import { navigate } from '@reach/router';
import { css } from '@emotion/react';
Expand All @@ -22,6 +22,8 @@ const HomePage = ({ data }) => {
allMarkdownRemark: { edges: whatsNewPosts },
} = data;

const [searchTerm, setSearchTerm] = useState('');

const { t } = useTranslation();

const mobileBreakpoint = '450px';
Expand All @@ -34,8 +36,6 @@ const HomePage = ({ data }) => {
};
});

const searchInputRef = useRef();

return (
<>
<h1
Expand All @@ -52,11 +52,12 @@ const HomePage = ({ data }) => {
<SearchInput
placeholder={t('home.search.placeholder')}
size={SearchInput.SIZE.LARGE}
ref={searchInputRef}
value={searchTerm || ''}
iconName={SearchInput.ICONS.SEARCH}
isIconClickable
alignIcon={SearchInput.ICON_ALIGNMENT.RIGHT}
onSubmit={() => navigate(`?q=${searchInputRef.current.value}`)}
onChange={(e) => setSearchTerm(e.target.value)}
onSubmit={() => navigate(`?q=${searchTerm || ''}`)}
css={css`
@media screen and (max-width: ${mobileBreakpoint}) {
margin-bottom: 1rem;
Expand Down

0 comments on commit 60c1ba4

Please sign in to comment.