mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 23:58:13 +08:00
fix(): properly scroll to input with scroll assist (#20742)
fixes #19589
This commit is contained in:
committed by
Liam DeBeasi
parent
0514b421ec
commit
e24060ecd9
@ -61,15 +61,32 @@ const jsSetFocus = (
|
||||
relocateInput(componentEl, inputEl, true, scrollData.inputSafeY);
|
||||
inputEl.focus();
|
||||
|
||||
/* tslint:disable-next-line */
|
||||
if (typeof window !== 'undefined') {
|
||||
let scrollContentTimeout: any;
|
||||
const scrollContent = async () => {
|
||||
// clean up listeners and timeouts
|
||||
if (scrollContentTimeout !== undefined) {
|
||||
clearTimeout(scrollContentTimeout);
|
||||
}
|
||||
window.removeEventListener('resize', scrollContent);
|
||||
|
||||
// scroll the input into place
|
||||
contentEl.scrollByPoint(0, scrollData.scrollAmount, scrollData.scrollDuration).then(() => {
|
||||
await contentEl.scrollByPoint(0, scrollData.scrollAmount, scrollData.scrollDuration);
|
||||
|
||||
// the scroll view is in the correct position now
|
||||
// give the native text input focus
|
||||
relocateInput(componentEl, inputEl, false, scrollData.inputSafeY);
|
||||
|
||||
// ensure this is the focused input
|
||||
inputEl.focus();
|
||||
});
|
||||
};
|
||||
|
||||
window.addEventListener('resize', scrollContent);
|
||||
|
||||
// fallback in case resize never fires
|
||||
scrollContentTimeout = setTimeout(scrollContent, 1000);
|
||||
}
|
||||
};
|
||||
|
||||
const hasPointerMoved = (threshold: number, startCoord: PointerCoordinates | undefined, endCoord: PointerCoordinates | undefined) => {
|
||||
|
||||
@ -23,8 +23,12 @@ export const startInputShims = (config: Config) => {
|
||||
const hideCaretMap = new WeakMap<HTMLElement, () => void>();
|
||||
const scrollAssistMap = new WeakMap<HTMLElement, () => void>();
|
||||
|
||||
const registerInput = (componentEl: HTMLElement) => {
|
||||
const inputEl = (componentEl.shadowRoot || componentEl).querySelector('input') || (componentEl.shadowRoot || componentEl).querySelector('textarea');
|
||||
const registerInput = async (componentEl: HTMLElement) => {
|
||||
if ((componentEl as any).componentOnReady) {
|
||||
await (componentEl as any).componentOnReady();
|
||||
}
|
||||
const inputRoot = componentEl.shadowRoot || componentEl;
|
||||
const inputEl = inputRoot.querySelector('input') || inputRoot.querySelector('textarea');
|
||||
const scrollEl = componentEl.closest('ion-content');
|
||||
|
||||
if (!inputEl) {
|
||||
|
||||
Reference in New Issue
Block a user