File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
7777 - Refactored data structure position and dimension (breaking change)
7878- ` <ActivityControlWidget /> `
7979 - display running time after label if there is an status info to prevent a third line
80+ - ` <SearchField /> `
81+ - internally forced to be managed controlled to keep ` onClearanceHandler ` independent from outer ` value ` property
8082
8183### Deprecated
8284
Original file line number Diff line number Diff line change @@ -36,20 +36,37 @@ export const SearchField = ({
3636 emptySearchInputMessage = "Enter search term" ,
3737 onClearanceHandler,
3838 onClearanceText = "Clear current search term" ,
39+ onChange,
3940 leftIcon = < Icon name = "operation-search" /> ,
4041 rightElement,
4142 ...otherProps
4243} : SearchFieldProps ) => {
44+ const [ value , setValue ] = React . useState < string > ( "" ) ;
45+
4346 const clearanceButton =
44- onClearanceHandler && otherProps . value ? (
47+ onClearanceHandler && value ? (
4548 < IconButton
4649 data-test-id = { otherProps [ "data-test-id" ] && `${ otherProps [ "data-test-id" ] } -clear-btn` }
4750 name = "operation-clear"
4851 text = { onClearanceText }
49- onClick = { onClearanceHandler }
52+ onClick = { ( ) => {
53+ setValue ( "" ) ;
54+ onClearanceHandler ( ) ;
55+ } }
5056 />
5157 ) : undefined ;
5258
59+ const changeHandlerProcess = ( e : React . ChangeEvent < HTMLInputElement > ) => {
60+ setValue ( e . target . value ) ;
61+ if ( onChange ) {
62+ onChange ( e ) ;
63+ }
64+ } ;
65+
66+ React . useEffect ( ( ) => {
67+ setValue ( otherProps . value ?? otherProps . defaultValue ?? "" ) ;
68+ } , [ otherProps . value , otherProps . defaultValue ] ) ;
69+
5370 return (
5471 < TextField
5572 className = {
@@ -68,7 +85,9 @@ export const SearchField = ({
6885 </ >
6986 )
7087 }
88+ onChange = { changeHandlerProcess }
7189 { ...otherProps }
90+ value = { value }
7291 type = { "search" }
7392 leftIcon = { leftIcon }
7493 round = { true }
Original file line number Diff line number Diff line change @@ -46,5 +46,5 @@ const SearchFieldWithClearanceIconTemplate: StoryFn<typeof SearchField> = (args)
4646export const SearchFieldWithClearanceIcon = SearchFieldWithClearanceIconTemplate . bind ( { } ) ;
4747SearchFieldWithClearanceIcon . args = {
4848 onClearanceHandler : null ,
49- onClearanceText : "" ,
49+ onClearanceText : "Clear field " ,
5050} ;
You can’t perform that action at this time.
0 commit comments