(
text: string,
private readonly _document: Document,
)
| 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 { |
nothing calls this directly
no outgoing calls
no test coverage detected