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

[Bug]: Cannot write to clipboard in Safari from change event of sp-action-menu #3687

Closed
1 task done
rickharris opened this issue Sep 29, 2023 · 4 comments · Fixed by #3689
Closed
1 task done

[Bug]: Cannot write to clipboard in Safari from change event of sp-action-menu #3687

rickharris opened this issue Sep 29, 2023 · 4 comments · Fixed by #3689

Comments

@rickharris
Copy link
Contributor

Code of conduct

  • I agree to follow this project's code of conduct.

Impacted component(s)

sp-action-menu

Expected behavior

I would like to be able to call navigator.clipboard.writeText from inside the change event of sp-action-menu. Safari only allows this function to be called as the result of a user interaction. Since this is the result of a user interaction it seems like this should work, and I would expect to be able to call navigator.clipboard.writeText successfully without an error.

It's not completely surprising or unexpected that this wouldn't work, but what's interesting to me is that it does work in react-spectrum's ActionMenu onAction callback, so I'm curious if it could be supported here.

Actual behavior

When calling navigator.clipboard.writeText from the change event in Safari it results in an error:

NotAllowedError
The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

Screenshots

No response

What browsers are you seeing the problem in?

Safari

How can we reproduce this issue?

  1. Go to https://codesandbox.io/s/solitary-worker-6f26cf?file=/src/App.js
  2. Click on the action menu trigger under the heading "react-spectrum ActionMenu"
  3. Observe that the string "rsCopy" is now in your clipboard
  4. Click on the action menu trigger under the heading "SWC sp-action-menu"
  5. Observe the NotAllowedError and "rsCopy" is still in your clipboard when it should be "spCopy"

Sample code that illustrates the problem

https://codesandbox.io/s/solitary-worker-6f26cf?file=/src/App.js

Logs taken while reproducing problem

No response

@rickharris rickharris added bug Something isn't working triage An issue needing triage labels Sep 29, 2023
@Westbrook
Copy link
Contributor

@rickharris our current unit testing config allows us to test this everywhere but in Safari... 😬 can you lend a hand and confirm that the selections in this demo are copied appropriately to the Clipboard in that context? I've manually confirmed in Safari 17 for macOS 13.6, but want to make sure this is doing the right thing in the context you encountered this initially.

If it looks good to you, we'll get a PR together and have this in the next release.

@jeffgint
Copy link

jeffgint commented Oct 2, 2023 via email

@rickharris
Copy link
Contributor Author

@Westbrook yep that demo is working how I'd hoped in Safari. Thanks!

@rick
Copy link

rick commented Oct 13, 2023

blingz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants