( componentEl: HTMLElement, inputEl: HTMLInputElement | HTMLTextAreaElement, inputRelativeY: number, disabledClonedInput = false )
| 32 | }; |
| 33 | |
| 34 | const addClone = ( |
| 35 | componentEl: HTMLElement, |
| 36 | inputEl: HTMLInputElement | HTMLTextAreaElement, |
| 37 | inputRelativeY: number, |
| 38 | disabledClonedInput = false |
| 39 | ) => { |
| 40 | // this allows for the actual input to receive the focus from |
| 41 | // the user's touch event, but before it receives focus, it |
| 42 | // moves the actual input to a location that will not screw |
| 43 | // up the app's layout, and does not allow the native browser |
| 44 | // to attempt to scroll the input into place (messing up headers/footers) |
| 45 | // the cloned input fills the area of where native input should be |
| 46 | // while the native input fakes out the browser by relocating itself |
| 47 | // before it receives the actual focus event |
| 48 | // We hide the focused input (with the visible caret) invisible by making it scale(0), |
| 49 | const parentEl = inputEl.parentNode!; |
| 50 | |
| 51 | // DOM WRITES |
| 52 | const clonedEl = inputEl.cloneNode(false) as HTMLInputElement | HTMLTextAreaElement; |
| 53 | clonedEl.classList.add('cloned-input'); |
| 54 | clonedEl.tabIndex = -1; |
| 55 | |
| 56 | /** |
| 57 | * Making the cloned input disabled prevents |
| 58 | * Chrome for Android from still scrolling |
| 59 | * the entire page since this cloned input |
| 60 | * will briefly be hidden by the keyboard |
| 61 | * even though it is not focused. |
| 62 | * |
| 63 | * This is not needed on iOS. While this |
| 64 | * does not cause functional issues on iOS, |
| 65 | * the input still appears slightly dimmed even |
| 66 | * if we set opacity: 1. |
| 67 | */ |
| 68 | if (disabledClonedInput) { |
| 69 | clonedEl.disabled = true; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Position the clone at the same horizontal offset as the native input |
| 74 | * to prevent the placeholder from overlapping start slot content (e.g., icons). |
| 75 | */ |
| 76 | const doc = componentEl.ownerDocument!; |
| 77 | const isRTL = doc.dir === 'rtl'; |
| 78 | |
| 79 | if (isRTL) { |
| 80 | const parentWidth = (parentEl as HTMLElement).offsetWidth; |
| 81 | const startOffset = parentWidth - inputEl.offsetLeft - inputEl.offsetWidth; |
| 82 | clonedEl.style.insetInlineStart = `${startOffset}px`; |
| 83 | } else { |
| 84 | clonedEl.style.insetInlineStart = `${inputEl.offsetLeft}px`; |
| 85 | } |
| 86 | |
| 87 | parentEl.appendChild(clonedEl); |
| 88 | cloneMap.set(componentEl, clonedEl); |
| 89 | |
| 90 | const tx = isRTL ? 9999 : -9999; |
| 91 | componentEl.style.pointerEvents = 'none'; |
no test coverage detected