( componentEl: HTMLElement, inputEl: HTMLInputElement | HTMLTextAreaElement, contentEl: HTMLElement | null, footerEl: HTMLIonFooterElement | null, keyboardHeight: number, enableScrollPadding: boolean, disableClonedInput = false, platformHeight = 0, waitForResize = true )
| 209 | }; |
| 210 | |
| 211 | const jsSetFocus = async ( |
| 212 | componentEl: HTMLElement, |
| 213 | inputEl: HTMLInputElement | HTMLTextAreaElement, |
| 214 | contentEl: HTMLElement | null, |
| 215 | footerEl: HTMLIonFooterElement | null, |
| 216 | keyboardHeight: number, |
| 217 | enableScrollPadding: boolean, |
| 218 | disableClonedInput = false, |
| 219 | platformHeight = 0, |
| 220 | waitForResize = true |
| 221 | ) => { |
| 222 | if (!contentEl && !footerEl) { |
| 223 | return; |
| 224 | } |
| 225 | const scrollData = getScrollData(componentEl, (contentEl || footerEl)!, keyboardHeight, platformHeight); |
| 226 | |
| 227 | if (contentEl && Math.abs(scrollData.scrollAmount) < 4) { |
| 228 | // the text input is in a safe position that doesn't |
| 229 | // require it to be scrolled into view, just set focus now |
| 230 | setManualFocus(inputEl); |
| 231 | |
| 232 | /** |
| 233 | * Even though the input does not need |
| 234 | * scroll assist, we should preserve the |
| 235 | * the scroll padding as users could be moving |
| 236 | * focus from an input that needs scroll padding |
| 237 | * to an input that does not need scroll padding. |
| 238 | * If we remove the scroll padding now, users will |
| 239 | * see the page jump. |
| 240 | */ |
| 241 | if (enableScrollPadding && contentEl !== null) { |
| 242 | setScrollPadding(contentEl, currentPadding); |
| 243 | setClearScrollPaddingListener(inputEl, contentEl, () => (currentPadding = 0)); |
| 244 | } |
| 245 | |
| 246 | return; |
| 247 | } |
| 248 | |
| 249 | // temporarily move the focus to the focus holder so the browser |
| 250 | // doesn't freak out while it's trying to get the input in place |
| 251 | // at this point the native text input still does not have focus |
| 252 | relocateInput(componentEl, inputEl, true, scrollData.inputSafeY, disableClonedInput); |
| 253 | setManualFocus(inputEl); |
| 254 | |
| 255 | /** |
| 256 | * If enabled, we can add scroll padding to |
| 257 | * the bottom of the content so that scroll assist |
| 258 | * has enough room to scroll the input above |
| 259 | * the keyboard. |
| 260 | */ |
| 261 | if (enableScrollPadding && contentEl) { |
| 262 | currentPadding = scrollData.scrollPadding; |
| 263 | setScrollPadding(contentEl, currentPadding); |
| 264 | } |
| 265 | |
| 266 | if (typeof window !== 'undefined') { |
| 267 | let scrollContentTimeout: ReturnType<typeof setTimeout>; |
| 268 | const scrollContent = async () => { |
no test coverage detected