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

Function onMove

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

Source from the content-addressed store, hash-verified

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

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