Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistant: Clear search when clicking outside on the input on desktop #2229

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste pour ma culture: pourquoi un span et pas un div ici?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ClickAwayListener attend un seul enfant, pas possible de mettre plusieurs enfants comme ici. Mais on veut englober les deux dans le ClickAwayListener. Sauf que pour ça je ne veux pas toucher au style, dans ces cas là perso j'utilise plus un span qu'un div, par habitude un display inline "casse" moins le style prédéfinit qu'un display block, mais je t'avoue que j'ai pas testé avec un div

<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
Loading