Skip to content

Commit d2524ee

Browse files
gkalpakSplaktar
authored andcommitted
refactor(docs-infra): simplify/improve CopierService hidden textarea creation (angular#38244)
This commit simplifies the creation of the temporary, hidden `<textarea>` element used by `CopierService` by switching from absolute to fixed positioning and not requiring page's scroll offset. It also makes the following minor improvements: - Make the element invisible (via `opacity: 0`). - Instruct screen-readers to ignore the element (via `aria-hidden: true`). NOTE: These improvements are based on Angular CDK's [PendingCopy][1] class and the changes proposed in PR angular/components#20073. [1]: https://github.com/angular/components/blob/89b5fa89d1437c3054c5/src/cdk/clipboard/pending-copy.ts PR Close angular#38244
1 parent f6d2af1 commit d2524ee

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

aio/src/app/shared/copier.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,13 @@ export class CopierService {
5959
style.padding = '0';
6060
style.margin = '0';
6161

62-
// Move element out of screen horizontally.
63-
style.position = 'absolute';
64-
style[ isRTL ? 'right' : 'left' ] = '-9999px';
65-
66-
// Move element to the same position vertically.
67-
const yPosition = window.pageYOffset || docElem.scrollTop;
68-
style.top = yPosition + 'px';
62+
// Make the element invisible and move it out of screen horizontally.
63+
style.opacity = '0';
64+
style.position = 'fixed';
65+
style.top = '0';
66+
style[isRTL ? 'right' : 'left'] = '-999em';
6967

68+
textArea.setAttribute('aria-hidden', 'true');
7069
textArea.setAttribute('readonly', '');
7170
textArea.value = text;
7271

0 commit comments

Comments
 (0)