Skip to content

Commit

Permalink
fix(modal): native keyboard will dismiss when bottom sheet is dragged
Browse files Browse the repository at this point in the history
Resolves #23878

Co-authored-by: EinfachHans <[email protected]>
  • Loading branch information
sean-perkins and EinfachHans committed Jan 24, 2022
1 parent 94d033c commit 42ffe56
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions core/src/components/modal/gestures/sheet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Animation } from '../../../interface';
import { GestureDetail, createGesture } from '../../../utils/gesture';
import { clamp, raf } from '../../../utils/helpers';
import { KEYBOARD_DID_CLOSE, KEYBOARD_DID_OPEN } from '../../../utils/keyboard/keyboard';
import { getBackdropValueForSheet } from '../utils';

export const createSheetGesture = (
Expand Down Expand Up @@ -42,6 +43,19 @@ export const createSheetGesture = (
const backdropAnimation = animation.childAnimations.find(ani => ani.id === 'backdropAnimation');
const maxBreakpoint = breakpoints[breakpoints.length - 1];

if (typeof window !== 'undefined') {
const keyboardOpenCallback = () => {
gesture.enable(false);
};

const keyboardCloseCallback = () => {
gesture.enable(true);
}

window.addEventListener(KEYBOARD_DID_OPEN, keyboardOpenCallback);
window.addEventListener(KEYBOARD_DID_CLOSE, keyboardCloseCallback);
}

/**
* After the entering animation completes,
* we need to set the animation to go from
Expand Down Expand Up @@ -80,6 +94,14 @@ export const createSheetGesture = (
return false;
}

if (typeof document !== 'undefined') {
const activeElement = baseEl.ownerDocument.activeElement as HTMLElement;
if (activeElement.matches('input,ion-input,textarea,ion-textarea')) {
// Dismisses the open keyboard when the sheet drag gesture is started.
activeElement.blur();
}
}

return true;
};

Expand Down Expand Up @@ -188,11 +210,11 @@ export const createSheetGesture = (
}
}

/**
* This must be a one time callback
* otherwise a new callback will
* be added every time onEnd runs.
*/
/**
* This must be a one time callback
* otherwise a new callback will
* be added every time onEnd runs.
*/
}, { oneTimeCallback: true })
.progressEnd(1, 0, 500);

Expand Down

0 comments on commit 42ffe56

Please sign in to comment.