Skip to content

Commit

Permalink
Fix search input value on navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
schiehll committed May 31, 2019
1 parent 1de9556 commit ec66dc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/components/shell/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import * as S from './styles'
const history = createBrowserHistory()

const Layout = ({ toggleLightSwitch, ...props }) => {
const searchInputRef = useRef(null)
const sideSheetRef = useRef(null)
const allKerbs = useRef([])
const [kerbs, setKerbs] = useState([])
Expand All @@ -45,6 +46,10 @@ const Layout = ({ toggleLightSwitch, ...props }) => {
}

const handleNavbarItemClick = itemId => {
if (searchInputRef.current) {
searchInputRef.current.value = ''
}

setActiveItem(itemId)
setKerbs(
itemId === '__DASHBOARD__'
Expand Down Expand Up @@ -179,7 +184,7 @@ const Layout = ({ toggleLightSwitch, ...props }) => {
<S.SideSheetButton onClick={toggleSideSheet}>
<FiMenu />
</S.SideSheetButton>
<Search onChange={handleSearch} />
<Search ref={searchInputRef} onChange={handleSearch} />
<LightSwitch light={lightContext} onClick={toggleLightSwitch} />
</S.Header>
<Widgets widgets={kerbs} />
Expand Down
7 changes: 4 additions & 3 deletions src/components/shell/search/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import React from 'react'
import React, { forwardRef } from 'react'
import PropTypes from 'prop-types'
import { FiSearch } from 'react-icons/fi'

import * as S from './styles'

const Search = ({ onChange, ...props }) => {
const Search = forwardRef(({ onChange, ...props }, ref) => {
return (
<S.Label {...props}>
<S.InputWrapper>
<FiSearch />
<S.StyledInput
ref={ref}
onChange={onChange}
type="search"
placeholder="Search..."
/>
</S.InputWrapper>
</S.Label>
)
}
})

Search.propTypes = {
onChange: PropTypes.func.isRequired
Expand Down

0 comments on commit ec66dc3

Please sign in to comment.