MCPcopy Create free account
hub / github.com/ionic-team/ionic-framework / addClone

Function addClone

core/src/utils/input-shims/hacks/common.ts:34–93  ·  view source on GitHub ↗
(
  componentEl: HTMLElement,
  inputEl: HTMLInputElement | HTMLTextAreaElement,
  inputRelativeY: number,
  disabledClonedInput = false
)

Source from the content-addressed store, hash-verified

32};
33
34const 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';

Callers 1

relocateInputFunction · 0.85

Calls 2

setMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected