Skip to content

Commit 4fb7ee1

Browse files
committed
Added a onClear callback function to SearchField
1 parent 8fb24c5 commit 4fb7ee1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/ui/SearchField/SearchField.stories.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export function Basic () {
9595
onSearch={e => onSearch(e)}
9696
showClear={boolean('Vis tøm', true)}
9797
showSearch={boolean('Vis søkeknapp', true)}
98+
onClear={() => console.log('onClear triggered')}
9899
/>
99100
<h3>Rounded</h3>
100101
<SearchField
@@ -104,6 +105,7 @@ export function Basic () {
104105
rounded
105106
showClear={boolean('Vis tøm', true)}
106107
showSearch={boolean('Vis søkeknapp', true)}
108+
onClear={() => console.log('onClear triggered')}
107109
/>
108110
</div>
109111
<br />

src/ui/SearchField/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Icon } from '../Icon'
99
import { Paragraph } from '../Typography'
1010
import { nanoid } from 'nanoid'
1111

12-
export function SearchField ({ placeholder, value, debounceMs, onSelected, rounded, onSearch, onChange, className, items, itemMapping, showDropdown, showClear, showSearch, onShowDropdown, onClickOutside, loading, loadingText, emptyText, style, onKeyDown, children, onBlur, onFocus, ...props }) {
12+
export function SearchField ({ placeholder, value, debounceMs, onSelected, rounded, onSearch, onChange, className, items, itemMapping, showDropdown, showClear, showSearch, onShowDropdown, onClickOutside, loading, loadingText, emptyText, style, onClear, onKeyDown, children, onBlur, onFocus, ...props }) {
1313
/*
1414
State
1515
*/
@@ -198,6 +198,7 @@ export function SearchField ({ placeholder, value, debounceMs, onSelected, round
198198
const handleClear = () => {
199199
handleChange({ target: { value: '' } })
200200
handleItemClick(undefined, undefined)
201+
if (onClear && typeof onClear === 'function') onClear()
201202
}
202203

203204
// Handles clicking the searchResult items
@@ -340,6 +341,7 @@ SearchField.propTypes = {
340341
]),
341342
onBlur: PropTypes.func,
342343
onChange: PropTypes.func,
344+
onClear: PropTypes.func,
343345
onClickOutside: PropTypes.func,
344346
onFocus: PropTypes.func,
345347
onKeyDown: PropTypes.func,

0 commit comments

Comments
 (0)