-
Notifications
You must be signed in to change notification settings - Fork 483
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
fix(@clayui/color-picker): Update hue slider to use html range input #5156
Conversation
fef1014
to
5445aef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @pat270 there are some things we need to think about before going ahead with this and maybe improve some things, more in relation to the implementation of React.
It also seems that we have some problems with Slider as you said, I had made some changes to try to understand but it seems that React has some problems with input range, I will continue researching more about this but maybe we will have to not use the input range but we can still make it accessible.
I'll leave some comments here about the improvements that can be made.
|
||
const removeListeners = () => { | ||
selectorActive.current = false; | ||
const [internalValue, setInternalValue] = useState<number>(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need another state here, because we also have a state in the parent component, in which case we have access to them which are value
and onChange
it is easier to maintain a source of truth than to have multiple states and keep synchronizing them all, this is also bad because of unnecessary rerenders.
|
||
const {onPointerMove, setXY, x, y} = usePointerPosition(containerRef); | ||
const {setXY, y} = usePointerPosition(containerRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this hook anymore and we don't need to set setXY
anymore because we are no longer using them here. It used to be just used to get x
information to deal with the position of the pointer, as we don't have it anymore, we don't need it anymore.
event.target.blur(); | ||
|
||
event.target.focus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand very well why we need this 😅, could you explain it better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a bug in FF input range with onPointerUp
. It keeps dragging the slider thumb even when the left mouse button is released. This didn't happen when I used onMouseUp
. The only way I could get it to work properly was blur then focus.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this is weird, I'll do some testing.
React.useEffect(() => { | ||
if (containerRef.current) { | ||
setXY({x: hueToX(value, containerRef.current), y}); | ||
} | ||
setInternalValue(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are going to use the parent state value
and onChange
we no longer need this to synchronize the values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't do this one due to #5156 (comment).
<ClayInput.Group> | ||
<ClayInput.GroupItem> | ||
<ClayInput | ||
data-testid="hInput" | ||
insetBefore | ||
max="360" | ||
min="0" | ||
onChange={(event) => { | ||
const value = event.target.value; | ||
|
||
let newVal = Number(value); | ||
|
||
if (newVal < 0) { | ||
newVal = 0; | ||
} else if (newVal > 360) { | ||
newVal = 360; | ||
} | ||
|
||
onHueChange(Math.round(newVal)); | ||
|
||
onColorChange(tinycolor({h: newVal, s, v})); | ||
}} | ||
type="number" | ||
value={hue} | ||
/> | ||
<ClayInput.GroupInsetItem before tag="label"> | ||
H | ||
</ClayInput.GroupInsetItem> | ||
</ClayInput.GroupItem> | ||
</ClayInput.Group> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are dealing with internal components we can move this composition to the Hue component, it is easier to keep the responsibility organized. As it is not an internal component, there is no problem rendering the bar along with the input.
window.removeEventListener('pointermove', onPointerMove); | ||
window.removeEventListener('pointerup', removeListeners); | ||
}; | ||
const handleOnChangeEnd = (event: any) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we won't have the internal state anymore, just add the onChange
callback as a property of the ClaySlider
, we won't need that anymore because we will be directly updating the parent state instead of the internal one.
@matuzalemsteles Thanks for the input, I'll update this pr with your suggestions. The problem is with the |
I see, I'm not sure if that would be the problem because internally the ClaySlider has the I had made some changes to just use Hue's Screen.Recording.2022-10-28.at.12.16.15.PM.mov |
The recording was exactly what was happening to me. |
5207588
to
31f8440
Compare
@pat270 I think the most ideal thing here to go with this would be to use |
- Styles the clay-range element and resets default values output by the clay-range-input-variant so base styles aren't duplicated by variants
…thumb for range with progress - This has better support for older browsers - Use the browser default thumb for clay-range-progress-none
- Adds new hue range input using native input range - Adds alpha input using native input range - Increase max height of Clay Color Dropdown Menu
Hey @pat270 I think we're going to have to refactor how we implement the ClaySlider to behave differently and that the mouse moves work correctly when the onChange changes, maybe the |
fixes #5137
I finally got this working with the range input. I used the
onKeyUp
andonPointerUp
events to update the Color Picker. The only problem with this is the map's hue doesn't update while dragging the thumb. Since I have something working, I can probably get it to work withonChange
only, just need to throttle or debounce the updates so it doesn't lag so much.In 87331f6#diff-47b43a95fa966e5189545f95207e5d85c86bb0a2ac02963ec706530728d79af5R39-R41, I had to blur then re-focus the input because FF has a range input issue when using
onPointerUp
. It fails to update the input value for some reason. This problem doesn't exist when usingonMouseUp
.