@@ -151,6 +151,7 @@ interface ColorPickerProps {
151151
152152function ColorPickerComponent ( props : ColorPickerProps ) {
153153 const [ color , setColor ] = React . useState ( props . color ) ;
154+ const [ isOpen , setOpen ] = React . useState ( false ) ;
154155 const debouncedOnChange = React . useCallback (
155156 debounce ( props . changeColor , 500 ) ,
156157 [ props . changeColor ] ,
@@ -164,6 +165,7 @@ function ColorPickerComponent(props: ColorPickerProps) {
164165 < Popover
165166 enforceFocus = { false }
166167 interactionKind = { PopoverInteractionKind . CLICK }
168+ isOpen = { isOpen }
167169 minimal
168170 modifiers = { {
169171 offset : {
@@ -176,22 +178,41 @@ function ColorPickerComponent(props: ColorPickerProps) {
176178 < StyledInputGroup
177179 leftIcon = {
178180 color ? (
179- < ColorIcon color = { color } />
181+ < ColorIcon color = { color } onClick = { ( ) => setOpen ( true ) } />
180182 ) : (
181- < NoColorIconWrapper >
183+ < NoColorIconWrapper onClick = { ( ) => setOpen ( true ) } >
182184 < NoColorIcon >
183185 < div className = "line" />
184186 </ NoColorIcon >
185187 </ NoColorIconWrapper >
186188 )
187189 }
190+ onBlur = { ( ) => {
191+ // Case 1
192+ // On Tab key press Input loses focus and onKeyUp handler is not called
193+ // To handle Tab key press onBlur event is used instead
194+ // As input will lose focus on Tab press
195+ // Case 2
196+ // if user clicks on ColorBoard blur is called first and color is not updated
197+ // to prevent that make sure to wait for color update before onBlur
198+ setTimeout ( ( ) => {
199+ setOpen ( false ) ;
200+ } , 100 ) ;
201+ } }
188202 onChange = { handleChangeColor }
203+ onFocus = { ( ) => setOpen ( true ) }
204+ onKeyUp = { ( e ) => {
205+ if ( e . key === "Enter" ) {
206+ setOpen ( ( state ) => ! state ) ;
207+ }
208+ } }
189209 placeholder = "enter color name or hex"
190210 value = { color }
191211 />
192212 < ColorBoard
193213 selectColor = { ( color ) => {
194214 setColor ( color ) ;
215+ setOpen ( false ) ;
195216 props . changeColor ( color ) ;
196217 } }
197218 selectedColor = { color }
0 commit comments