MCPcopy Create free account
hub / github.com/angular/components / constructor

Method constructor

src/cdk/clipboard/pending-copy.ts:25–45  ·  view source on GitHub ↗
(
    text: string,
    private readonly _document: Document,
  )

Source from the content-addressed store, hash-verified

23 private _textarea: HTMLTextAreaElement | undefined;
24
25 constructor(
26 text: string,
27 private readonly _document: Document,
28 ) {
29 const textarea = (this._textarea = this._document.createElement('textarea'));
30 const styles = textarea.style;
31
32 // Hide the element for display and accessibility. Set a fixed position so the page layout
33 // isn't affected. We use `fixed` with `top: 0`, because focus is moved into the textarea
34 // for a split second and if it's off-screen, some browsers will attempt to scroll it into view.
35 styles.position = 'fixed';
36 styles.top = styles.opacity = '0';
37 styles.left = '-999em';
38 textarea.setAttribute('aria-hidden', 'true');
39 textarea.value = text;
40 // Making the textarea `readonly` prevents the screen from jumping on iOS Safari (see #25169).
41 textarea.readOnly = true;
42 // The element needs to be inserted into the fullscreen container, if the page
43 // is in fullscreen mode, otherwise the browser won't execute the copy command.
44 (this._document.fullscreenElement || this._document.body).appendChild(textarea);
45 }
46
47 /** Finishes copying the text. */
48 copy(): boolean {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected