From f1582247d0e88a8b41e38eec6820e1bf257de943 Mon Sep 17 00:00:00 2001 From: KumJungMin <37934668+KumJungMin@users.noreply.github.com> Date: Mon, 24 Jun 2024 09:19:36 +0900 Subject: [PATCH 1/2] fix: apply s and b of previous hsb to this.hsbValue --- components/lib/colorpicker/ColorPicker.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/components/lib/colorpicker/ColorPicker.js b/components/lib/colorpicker/ColorPicker.js index b80a447114..0107c8eb4b 100644 --- a/components/lib/colorpicker/ColorPicker.js +++ b/components/lib/colorpicker/ColorPicker.js @@ -97,13 +97,21 @@ export const ColorPicker = React.memo( !isUnstyled && DomHandler.addClass(elementRef.current, 'p-colorpicker-dragging'); }; + const getPositionY = (event) => { + if (event.pageY !== undefined) return event.pageY; + else if (event.touches !== undefined) return event.touches[0].pageY; + else return 0; + }; + const pickHue = (event) => { - const top = hueViewRef.current.getBoundingClientRect().top + (window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0); + const top = hueViewRef.current.getBoundingClientRect().top + (window.scrollY || document.documentElement.scrollTop || document.body.scrollTop || 0); + const yPos = getPositionY(event); + const hue = Math.floor((360 * (150 - Math.max(0, Math.min(150, yPos - top)))) / 150); hsbValue.current = validateHSB({ - h: Math.floor((360 * (150 - Math.max(0, Math.min(150, (event.pageY || event.changedTouches[0].pageY) - top)))) / 150), - s: 100, - b: 100 + h: hue, + s: hsbValue.current.s, + b: hsbValue.current.b }); updateColorSelector(); From 63881b09ff842091d4921d7d0747747b4ca58147 Mon Sep 17 00:00:00 2001 From: KumJungMin <37934668+KumJungMin@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:05:29 +0900 Subject: [PATCH 2/2] fix: get touchValue in event.changedTouches --- components/lib/colorpicker/ColorPicker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/lib/colorpicker/ColorPicker.js b/components/lib/colorpicker/ColorPicker.js index 0107c8eb4b..964e71ca2c 100644 --- a/components/lib/colorpicker/ColorPicker.js +++ b/components/lib/colorpicker/ColorPicker.js @@ -99,7 +99,7 @@ export const ColorPicker = React.memo( const getPositionY = (event) => { if (event.pageY !== undefined) return event.pageY; - else if (event.touches !== undefined) return event.touches[0].pageY; + else if (event.changedTouches !== undefined) return event.changedTouches[0].pageY; else return 0; };