diff --git a/src/cdk/clipboard/pending-copy.ts b/src/cdk/clipboard/pending-copy.ts index 0250999b0c7b..9db67feb66d7 100644 --- a/src/cdk/clipboard/pending-copy.ts +++ b/src/cdk/clipboard/pending-copy.ts @@ -26,11 +26,12 @@ export class PendingCopy { const textarea = this._textarea = this._document.createElement('textarea'); const styles = textarea.style; - // Hide the element for display and accessibility. Set an - // absolute position so the page layout isn't affected. - styles.opacity = '0'; - styles.position = 'absolute'; - styles.left = styles.top = '-999em'; + // Hide the element for display and accessibility. Set a fixed position so the page layout + // isn't affected. We use `fixed` with `top: 0`, because focus is moved into the textarea + // for a split second and if it's off-screen, some browsers will attempt to scroll it into view. + styles.position = 'fixed'; + styles.top = styles.opacity = '0'; + styles.left = '-999em'; textarea.setAttribute('aria-hidden', 'true'); textarea.value = text; this._document.body.appendChild(textarea);