fix(docs-infra): preserve focus on copy (and prevent scrolling to bottom on IE11) (#38244)
fix(docs-infra): preserve focus on copy (and prevent scrolling to bottom on IE11) (#38244)

The `CopierService` is used for copying text to the user's clipboard. It
is, for example, used in `CodeComponent` to copy example code snippets.
This is implemented by creating a temporary, hidden `<textarea>`
elements, setting its value to the text that needs to be copied,
executing the `copy` command and finally removing the element from the
DOM.

Previously, as a result of `CopierService`'s implementation, the focused
element would lose focus, while the temporary `<textarea>` element would
implicitly gain focus when selecting its contents. This had an even
worse side-effect on IE11, which seems to scroll to the bottom of the
containing element (here `<body>`) when the focused element is removed.

This commit fixes these issues by keeping track of the previously
focused element and restoring its focus after the copy operation.

NOTE: This fix is inspired by Angular CDK's [PendingCopy][1] class.

[1]: https://github.com/angular/components/blob/89b5fa89d1437c3054c5/src/cdk/clipboard/pending-copy.ts

Fixes #37796

PR Close #38244

IdeaBlade/angular,gkalpak/angular,IdeaBlade/angular,gdi2290/angular,manekinekko/angular,angular-indonesia/angular,ocombe/angular,IdeaBlade/angular,JiaLiPassion/angular,alxhub/angular,blesh/angular,gdi2290/angular,wKoza/angular,ocombe/angular,alxhub/angular,blesh/angular,manekinekko/angular,shairez/angular,gdi2290/angular,angular/angular,brandonroberts/angular,angular-indonesia/angular,ocombe/angular,wKoza/angular,manekinekko/angular,brandonroberts/angular,shairez/angular,gnomeontherun/angular,IdeaBlade/angular,blesh/angular,brandonroberts/angular,gkalpak/angular,wKoza/angular,manekinekko/angular,alxhub/angular,gnomeontherun/angular,alxhub/angular,brandonroberts/angular,IdeaBlade/angular,JiaLiPassion/angular,alxhub/angular,mgechev/angular,blesh/angular,gnomeontherun/angular,JiaLiPassion/angular,manekinekko/angular,angular/angular,ocombe/angular,JiaLiPassion/angular,shairez/angular,wKoza/angular,gkalpak/angular,gdi2290/angular,shairez/angular,angular/angular,angular-indonesia/angular,mgechev/angular,mgechev/angular,mgechev/angular,ocombe/angular,mgechev/angular,wKoza/angular,angular-indonesia/angular,brandonroberts/angular,angular/angular,gnomeontherun/angular,brandonroberts/angular,wKoza/angular,gdi2290/angular,gkalpak/angular,manekinekko/angular,shairez/angular,ocombe/angular,gdi2290/angular,blesh/angular