Skip to content

Commit

Permalink
fix(cdk/clipboard): not working inside fullscreen element (angular#27456
Browse files Browse the repository at this point in the history
)

Fixes that the clipboard service didn't work when the page is fullscreen.

Fixes angular#27447.
  • Loading branch information
crisbeto authored and stephenrca committed Aug 2, 2023
1 parent db860ee commit 90823c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cdk/clipboard/pending-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export class PendingCopy {
textarea.value = text;
// Making the textarea `readonly` prevents the screen from jumping on iOS Safari (see #25169).
textarea.readOnly = true;
this._document.body.appendChild(textarea);
// The element needs to be inserted into the fullscreen container, if the page
// is in fullscreen mode, otherwise the browser won't execute the copy command.
(this._document.fullscreenElement || this._document.body).appendChild(textarea);
}

/** Finishes copying the text. */
Expand Down
5 changes: 5 additions & 0 deletions src/dev-app/clipboard/clipboard-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
<button
[cdkCopyToClipboard]="value"
[cdkCopyToClipboardAttempts]="attempts">Copy to clipboard via directive</button>

<section>
<label for="testing-area">Testing area</label>
<textarea id="testing-area" cols="30" rows="5"></textarea>
</section>

0 comments on commit 90823c7

Please sign in to comment.