Skip to content
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

Prevent scroll jump on iOS #369

Closed
wants to merge 2 commits into from
Closed

Conversation

newsroomdev
Copy link

Fixes #347

Use the select method on fakeElem, instead of focus. Passes npm test and is more reliable than window.scrollTo. Solution courtesy of this StackOverflow comment

cc @zenorocha

@hrag
Copy link

hrag commented Feb 6, 2017

Please merge this! 😬

@zenorocha zenorocha self-requested a review February 6, 2017 16:15
Copy link
Owner

@zenorocha zenorocha left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this pull request @geraldarthur, can you also confirm if this fix works in our supported browsers? https://github.com/zenorocha/clipboard.js#browser-support

@@ -1,3 +1,4 @@
.DS_Store
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please remove this line? This should be ignored in your .gitignore_global file.

@@ -452,15 +452,17 @@ module.exports = E;
this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
// Move element to the same position vertically
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
console.log("yPosition", yPosition);
// this.fakeElem.addEventListener('focus', window.scrollTo(0, yPosition));
Copy link
Owner

Choose a reason for hiding this comment

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

Could you please remove this console.log and the commented code block?

this.selectedText = select(this.fakeElem);
this.fakeElem.select();
this.fakeElem.setSelectionRange(0, this.fakeElem.value.length);
this.selectedText = this.fakeElem.value;
Copy link
Owner

Choose a reason for hiding this comment

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

The select package already do this kind of logic https://github.com/zenorocha/select/blob/master/src/select.js#L9-L13. The difference is that it calls focus() instead of select(). Can you use the select package and submit a PR to it?

zenorocha added a commit that referenced this pull request Feb 8, 2017
@zenorocha
Copy link
Owner

I went ahead and commited this so we could have this fixed faster.

Thanks a lot for your work @geraldarthur. Let me know if everything is working fine for you guys on v1.6.0.

@zenorocha zenorocha closed this Feb 8, 2017
@hrag
Copy link

hrag commented Feb 8, 2017

This fix is working great for me. Thanks to the both of you! @zenorocha @geraldarthur

@newsroomdev
Copy link
Author

thanks so much @zenorocha! had a few deadline creep up on me yesterday, but appreciate your help. i'll test out the latest later this week. cheers!

@thanhdnh
Copy link

thanhdnh commented Mar 25, 2017

No, it no works for me. I use clipboardjs 1.6, on ios 10.xxx, scrolls to data-clipboard-target element when I copy/cut. I have an input element (data-clipboard-target) at the top of page (position:fixed), I scroll down, down and down to the my button copy. And after copy, It brings me to data-clipboard-target position. I don't want that. I want it no moves.

cdll pushed a commit to x78w/clipboard.js that referenced this pull request Jul 14, 2020
cdll added a commit to x78w/clipboard.js that referenced this pull request Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants