Fix drag boundary not updating when board is moved on screen #149
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When
allowDragOutsideBoard
is false, pieces cannot be dragged outside of a bounding rectangle defined over the board's position on the screen. However, after the board has been rendered, this bounding rectangle is not updated when the screen is scrolled, the board is resized, or any other change in the DOM causes it's position on the screen to change.This change simplifies the manner in which the board's bounds are calculated and stored. Instead of trying to calculate and memoize the position of the board on the screen in advance, the board's bounds are calculated only when the dragging state changes.
Example of Incorrect Behaviour
This example from the Storybook shows how the bounding rectangle restricting where a piece may be dragged is not updated when the element moves on the screen. Here I have moved the board by manipulating other elements in the DOM, indicating that resize and scroll are not the only types of events that could trigger this behaviour.
before.mov
Example of Improved Behaviour
This example from the Storybook after this change is applied shows that the bounding rectangle restricting where a piece may be dragged continues to match the visible location of the board when the board is moved from its initial position.
after.mov