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

Copy command failed in ios Safari if -webkit-user-select is none for created span #75

Closed
Amareis opened this issue Jan 23, 2018 · 6 comments

Comments

@Amareis
Copy link

Amareis commented Jan 23, 2018

https://jsfiddle.net/561qcehd/11/
It can be workarounded easily if change css selector for rule to something more specific than body, but i think that library should handle this case, e.g. using inline styles for created span with -webkit-user-select: text;.

@lgarron
Copy link
Owner

lgarron commented Feb 9, 2018

Oh, fun. It should be easy to add -webkit-user-select: text !important; inline.

var tempElem = document.createElement("div");
// Place some text in the elem so that Safari has something to select.
tempElem.textContent = "temporary element";
document.body.appendChild(tempElem);

Do you know how other browsers behave?

lgarron added a commit that referenced this issue Feb 9, 2018
@lgarron lgarron closed this as completed in e2b61c2 Feb 9, 2018
lgarron added a commit that referenced this issue Feb 9, 2018
Changes:
- Support copying on iOS Safari even if the document body is set to `-webkit-user-select: none`. #75
@lgarron lgarron reopened this Feb 9, 2018
@lgarron
Copy link
Owner

lgarron commented Feb 9, 2018

So, I thought I had a solution for this, but it doesn't appear to work if -webkit-user-select: none is set on the entire body rather than a surrounding element. :-(

@lgarron
Copy link
Owner

lgarron commented Feb 9, 2018

So, I thought I had a solution for this, but it doesn't appear to work if -webkit-user-select: none is set on the entire body rather than a surrounding element. :-(

Looks like I misunderstood that you can't set !important when setting an individual CSS property in JS. I've worked around that.

Could you check that v2.4.2 works for you?

@Amareis
Copy link
Author

Amareis commented Feb 9, 2018

You don't need to set important for element styles cause it already has max prority. Seem to 2.4.2 worked totally ok on mobile safari, checked in https://jsfiddle.net/561qcehd/12/ (it's jsfiddle from top message, but with 2.4.2 version).

@lgarron
Copy link
Owner

lgarron commented Feb 9, 2018

You don't need to set important for element styles cause it already has max prority.

On my computer, setting !important on the element appears to be necessary if the enclosing element also has !important.

Thanks for verifying the fix!

@Amareis
Copy link
Author

Amareis commented Feb 9, 2018

Yeah, if global styles has !important, it breaks all the things. But even in https://jsfiddle.net/561qcehd/13/ (with global !important) all works in mobile safari, so thank you for fix.

lgarron added a commit that referenced this issue Feb 9, 2018
Changes:
- Fix copying `text/html` on desktop Safari when the body has `-webkit-user-select: none` set. #75.
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

No branches or pull requests

2 participants