Skip to content

fix(clipboard): scroll position changing while copying on some browsers #20073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2020

Conversation

crisbeto
Copy link
Member

The clipboard module works by creating a textarea dynamically, focusing it and copying its content. In order to prevent it from affecting the page layout, we put it at -999em off-screen, but the problem is that some browsers will try to move it into the view on focus by scrolling up.

These changes use position: fixed and anchor the textarea to the top of the page so vertically it's within the viewport.

The clipboard module works by creating a `textarea` dynamically, focusing it and copying its content. In order to prevent it from affecting the page layout, we put it at `-999em` off-screen, but the problem is that some browsers will try to move it into the view on focus by scrolling up.

These changes use `position: fixed` and anchor the textarea to the top of the page so vertically it's within the viewport.
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release labels Jul 22, 2020
@crisbeto crisbeto requested a review from jelbourn as a code owner July 22, 2020 18:19
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jul 22, 2020
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jelbourn jelbourn added lgtm action: merge The PR is ready for merge by the caretaker labels Jul 22, 2020
@saifabusaleh
Copy link
Contributor

saifabusaleh commented Jul 25, 2020

Hi @crisbeto, srry I am late to this :(

did you checked if the fix is working in IE11?

There is same issue in angular.io copy to clipboard

See issue here: angular/angular#37796

@crisbeto
Copy link
Member Author

I was testing against IE11 specifically when I saw the issue. This won't fix angular.io since they aren't using the CDK though.

@saifabusaleh
Copy link
Contributor

saifabusaleh commented Jul 25, 2020

@crisbeto Ok 💯

It would be great if you can give any suggestions to solution in the other issue, because I tried to apply the code here to angular.io issue and it didn't fix it..
Thanks

@jelbourn jelbourn merged commit a6f1a33 into angular:master Jul 28, 2020
jelbourn pushed a commit that referenced this pull request Jul 28, 2020
…rs (#20073)

The clipboard module works by creating a `textarea` dynamically, focusing it and copying its content. In order to prevent it from affecting the page layout, we put it at `-999em` off-screen, but the problem is that some browsers will try to move it into the view on focus by scrolling up.

These changes use `position: fixed` and anchor the textarea to the top of the page so vertically it's within the viewport.

(cherry picked from commit a6f1a33)
gkalpak added a commit to gkalpak/angular that referenced this pull request Jul 29, 2020
…a creation

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
mhevery pushed a commit to angular/angular that referenced this pull request Jul 29, 2020
…a creation (#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 #38244
mhevery pushed a commit to angular/angular that referenced this pull request Jul 29, 2020
…a creation (#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 #38244
Splaktar pushed a commit to angular-hispano/angular that referenced this pull request Aug 8, 2020
…a 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
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants