Skip to content

Commit

Permalink
feat(Assistant): Clear search when clicking outside on the input on d…
Browse files Browse the repository at this point in the history
…esktop
  • Loading branch information
JF-Cozy committed Oct 28, 2024
1 parent fb001fc commit 4e9461d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/assistant/Search/SearchBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const SearchBar = () => {
value={inputValue}
onClick={handleClick}
onKeyDown={handleKeyDown}
onClear={handleClear}
onChange={handleChange}
/>
)
Expand Down
39 changes: 21 additions & 18 deletions src/assistant/Search/SearchBarDesktop.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useRef } from 'react'

import ClickAwayListener from 'cozy-ui/transpiled/react/ClickAwayListener'
import SearchBar from 'cozy-ui/transpiled/react/SearchBar'
import Icon from 'cozy-ui/transpiled/react/Icon'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
Expand All @@ -11,29 +12,31 @@ import { useSearch } from './SearchProvider'

import styles from './styles.styl'

const SearchBarDesktop = ({ value, onClick, onKeyDown, onChange }) => {
const SearchBarDesktop = ({ value, onClick, onKeyDown, onClear, onChange }) => {
const { t } = useI18n()
const { searchValue } = useSearch()
const searchRef = useRef()

return (
<>
<SearchBar
className={searchValue ? styles['searchBarDesktop--result'] : ''}
ref={searchRef}
size="large"
icon={<Icon className="u-mh-1" icon={AssistantIcon} size={32} />}
placeholder={t('assistant.search.placeholder')}
value={value}
componentsProps={{
inputBase: { onKeyDown }
}}
disabledClear
disabledFocus={value !== ''}
onChange={onChange}
/>
{searchValue && <ResultMenu anchorRef={searchRef} onClick={onClick} />}
</>
<ClickAwayListener onClickAway={onClear}>
<span>
<SearchBar
className={searchValue ? styles['searchBarDesktop--result'] : ''}
ref={searchRef}
size="large"
icon={<Icon className="u-mh-1" icon={AssistantIcon} size={32} />}
placeholder={t('assistant.search.placeholder')}
value={value}
componentsProps={{
inputBase: { onKeyDown }
}}
disabledClear
disabledFocus={value !== ''}
onChange={onChange}
/>
{searchValue && <ResultMenu anchorRef={searchRef} onClick={onClick} />}
</span>
</ClickAwayListener>
)
}

Expand Down

0 comments on commit 4e9461d

Please sign in to comment.