Skip to content

Commit 3ac7276

Browse files
omgovichVlad Shilov
authored andcommitted
Rename method and tweak comments
1 parent 30bb7a7 commit 3ac7276

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/components/common/Interactive.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ export interface Interaction {
1010
// Check if an event was triggered by touch
1111
const isTouch = (event: MouseEvent | TouchEvent): event is TouchEvent => "touches" in event;
1212

13-
const getPoint = (touches: TouchList, touchId: null | number): Touch => {
13+
// Finds a proper touch point by its identifier
14+
const getTouchPoint = (touches: TouchList, touchId: null | number): Touch => {
1415
for (let i = 0; i < touches.length; i++) {
15-
if (touches[i].identifier === touchId) {
16-
return touches[i];
17-
}
16+
if (touches[i].identifier === touchId) return touches[i];
1817
}
1918
return touches[0];
2019
};
@@ -28,7 +27,7 @@ const getRelativePosition = (
2827
const rect = node.getBoundingClientRect();
2928

3029
// Get user's pointer position from `touches` array if it's a `TouchEvent`
31-
const pointer = isTouch(event) ? getPoint(event.touches, touchId) : (event as MouseEvent);
30+
const pointer = isTouch(event) ? getTouchPoint(event.touches, touchId) : (event as MouseEvent);
3231

3332
return {
3433
left: clamp((pointer.pageX - (rect.left + window.pageXOffset)) / rect.width),
@@ -71,13 +70,12 @@ const InteractiveBase = ({ onMove, onKey, ...rest }: Props) => {
7170
preventDefaultMove(nativeEvent);
7271

7372
if (isInvalid(nativeEvent, hasTouch.current) || !el) return;
73+
7474
if (isTouch(nativeEvent)) {
7575
hasTouch.current = true;
7676
touchId.current = nativeEvent.changedTouches[0].identifier;
7777
}
7878

79-
// The node/ref must actually exist when user start an interaction.
80-
// We won't suppress the ESLint warning though, as it should probably be something to be aware of.
8179
el.focus();
8280
onMoveCallback(getRelativePosition(el, nativeEvent, touchId.current));
8381
toggleDocumentEvents(true);

tests/components.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ it("Doesn't call `onChange` when user changes a hue of a grayscale color", () =>
9292
const hue = container.querySelector(".react-colorful__hue .react-colorful__interactive");
9393

9494
fireEvent.touchStart(hue, {
95-
changedTouches: [{ pageX: 0, pageY: 0 }],
9695
touches: [{ pageX: 0, pageY: 0 }],
9796
});
9897
fireEvent.touchMove(hue, { touches: [{ pageX: 100, pageY: 0 }] });

0 commit comments

Comments
 (0)