I have a component that looks as follows, visually.
Here is a simplified codepen recreation .
The main problem comes in here:
<div className={styles.colorPicker}>
<input
readOnly
type="text"
value={color}
onFocus={this.showColorPalette}
onBlur={this.hideColorPalette}
/>
<Palette
color={color}
onSelect={this.selectColor}
/>
</div>
The intended behavior is that, when they blur the component, the color palette should hide. however , if they clicked on something in the color palette, it should not hide the palette.
Because clicking on the color palette will blur the input, it will hide the palette. I can't find a way to reconcile the palette's onClick
method with the input's onBlur
method in such a way that one overrides the other.
Is there a way to do this in react?
just tried something using onMouseEnter
and onMousLeave
to conditionally trigger blur()
. By this the color pallette will be visible for picking color and will be blurred when the color is picked or click outside the input box.
Check the updatde pen
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.