Skip to content

Commit

Permalink
Fix(ColorPicker): apply s and b of previous hsb to hsbValue (#6788)
Browse files Browse the repository at this point in the history
  • Loading branch information
KumJungMin authored Jun 25, 2024
1 parent c209792 commit da22444
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions components/lib/colorpicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.changedTouches !== undefined) return event.changedTouches[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();
Expand Down

0 comments on commit da22444

Please sign in to comment.