MCPcopy Create free account
hub / github.com/adobe/react-spectrum / onMove

Function onMove

packages/react-aria/src/slider/useSliderThumb.ts:183–210  ·  view source on GitHub ↗
({deltaX, deltaY, pointerType, shiftKey})

Source from the content-addressed store, hash-verified

181 state.setThumbDragging(index, true);
182 },
183 onMove({deltaX, deltaY, pointerType, shiftKey}) {
184 const {getThumbPercent, setThumbPercent, decrementThumb, incrementThumb, step, pageSize} =
185 state;
186 if (!trackRef.current) {
187 return;
188 }
189 let {width, height} = trackRef.current.getBoundingClientRect();
190 let size = isVertical ? height : width;
191
192 if (currentPosition.current == null) {
193 currentPosition.current = getThumbPercent(index) * size;
194 }
195 if (pointerType === 'keyboard') {
196 if ((deltaX > 0 && reverseX) || (deltaX < 0 && !reverseX) || deltaY > 0) {
197 decrementThumb(index, shiftKey ? pageSize : step);
198 } else {
199 incrementThumb(index, shiftKey ? pageSize : step);
200 }
201 } else {
202 let delta = isVertical ? deltaY : deltaX;
203 if (isVertical || reverseX) {
204 delta = -delta;
205 }
206
207 currentPosition.current += delta;
208 setThumbPercent(index, clamp(currentPosition.current / size, 0, 1));
209 }
210 },
211 onMoveEnd() {
212 state.setThumbDragging(index, false);
213 }

Callers

nothing calls this directly

Calls 4

clampFunction · 0.90
decrementThumbFunction · 0.85
incrementThumbFunction · 0.85
setThumbPercentFunction · 0.85

Tested by

no test coverage detected