Skip to content

Commit

Permalink
fix: when onResizeStart return false it should stop (#978)
Browse files Browse the repository at this point in the history
- when `onResizeStart` returns `false`, for example when editor `commitCurrentEdit()` fails, then the column resize shouldn't be allowed
  • Loading branch information
ghiscoding authored Jan 17, 2024
1 parent ab634eb commit 8c659c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion examples/example4-model-esm.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ <h2>View Source:</h2>

function requiredFieldValidator(value) {
if (value == null || value == undefined || !value.length) {
return {valid: false, msg: "This is a required field"};
return {valid: false, msg: 'This is a required field'};
} else if (!/^(task\s\d+)*$/i.test(value)) {
return { valid: false, msg: 'Your title is invalid, it must start with "Task" followed by a number.' };
}
else {
return {valid: true, msg: null};
Expand Down
14 changes: 8 additions & 6 deletions src/slick.interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,18 +231,20 @@ export function Resizable(options: ResizableOption) {

function executeResizeCallbackWhenDefined(callback?: Function, e?: MouseEvent | TouchEvent | Touch) {
if (typeof callback === 'function') {
callback(e, { resizeableElement, resizeableHandleElement });
return callback(e, { resizeableElement, resizeableHandleElement });
}
}

function resizeStartHandler(e: MouseEvent | TouchEvent) {
e.preventDefault();
const event = (e as TouchEvent).touches ? (e as TouchEvent).changedTouches[0] : e;
executeResizeCallbackWhenDefined(onResizeStart, event);
document.body.addEventListener('mousemove', resizingHandler);
document.body.addEventListener('mouseup', resizeEndHandler);
document.body.addEventListener('touchmove', resizingHandler);
document.body.addEventListener('touchend', resizeEndHandler);
const result = executeResizeCallbackWhenDefined(onResizeStart, event);
if (result !== false) {
document.body.addEventListener('mousemove', resizingHandler);
document.body.addEventListener('mouseup', resizeEndHandler);
document.body.addEventListener('touchmove', resizingHandler);
document.body.addEventListener('touchend', resizeEndHandler);
}
}

function resizingHandler(e: MouseEvent | TouchEvent) {
Expand Down

0 comments on commit 8c659c9

Please sign in to comment.