Skip to content

Commit

Permalink
Fixed bug when KeyboardSensor can fully scroll a single axis
Browse files Browse the repository at this point in the history
Fixed a bug in the `KeyboardSensor` where it would not move the draggable on the horizontal axis if it could fully scroll to the new vertical coordinates, and would not move the draggable on the vertical axis if it could fully scroll to the new horizontal coordinates.
  • Loading branch information
clauderic committed May 21, 2022
1 parent 33e6dd2 commit 750d726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/keyboard-sensor-bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dnd-kit/core': patch
---

Fixed a bug in the `KeyboardSensor` where it would not move the draggable on the horizontal axis if it could fully scroll to the new vertical coordinates, and would not move the draggable on the vertical axis if it could fully scroll to the new horizontal coordinates.
4 changes: 2 additions & 2 deletions packages/core/src/sensors/keyboard/KeyboardSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class KeyboardSensor implements SensorInstance {
(direction === KeyboardCode.Left &&
newScrollCoordinates >= minScroll.x);

if (canFullyScrollToNewCoordinates) {
if (canFullyScrollToNewCoordinates && !coordinatesDelta.y) {
// We don't need to update coordinates, the scroll adjustment alone will trigger
// logic to auto-detect the new container we are over
scrollContainer.scrollTo({
Expand Down Expand Up @@ -205,7 +205,7 @@ export class KeyboardSensor implements SensorInstance {
(direction === KeyboardCode.Up &&
newScrollCoordinates >= minScroll.y);

if (canFullyScrollToNewCoordinates) {
if (canFullyScrollToNewCoordinates && !coordinatesDelta.x) {
// We don't need to update coordinates, the scroll adjustment alone will trigger
// logic to auto-detect the new container we are over
scrollContainer.scrollTo({
Expand Down

0 comments on commit 750d726

Please sign in to comment.