-
-
Notifications
You must be signed in to change notification settings - Fork 252
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
added fallback for clipboard copy and context menu paste #673
added fallback for clipboard copy and context menu paste #673
Conversation
sessionStorage.getItem("localClipboard") || ""; | ||
|
||
try { | ||
clipboardText = await navigator.clipboard.readText(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bgareth for creating this PR!! ❤️
Just a suggestion if possible:
Accessing the clipboard will still cause an uncomfortable UX. To improve the user experience, it's best to provide a setting that allows users to enable or disable clipboard functionality. For instance, we can introduce a setting called enableClipboard, which defaults to true. If a user prefers not to use clipboard access, they can disable it during initialization. This approach ensures a smoother UX, preventing unwanted pop-ups in Chrome or special paste option in Safari.
To implement this, we need to find all occurrences of navigator.clipboard
and document.execCommand('copy'/'paste')
and replace them with proper handling based on the enableClipboard setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @bgareth for the PR, thank you @umermughal for reviewing it!
@umermughal realistically, are there instances when a user would not prefer FortuneSheet accessing their clipboard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like I have requested a feature, and you are fixing bug :) So things are looks good to me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Corbe30 I've observed (general observation not related to this FortuneSheet) that people often feel uncomfortable granting permissions, especially when security is a concern and don't have any stats
https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#security_considerations
what if the password is in clipboard?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm makes sense, thanks for clarifying! Let's pick this in separate PR after we merge this. I'll create an issue to track it ✨
Edit: #675
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@umermughal from the above discussion i feel the word "users" is being used for both the developers using FS and the end user using the web application. in almost every conceivable situation i can think of using a spreadsheet - youd want to copy paste stuff to the workbook. the security consideration is quite generic tbh (since navigator class only works for secure contexts) and the only plausible reason to have this config would be to not show a permissions popup to your end user. open to a pr on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@umermughal can you please confirm if you imply that the developer should be able to force the sheet to run in this "fallback" mode by using this prop which will block global clipboard access? in that case it sounds fair.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sanchit3008 Yes, I want this feature for the developer
This PR is about addressing context menu paste when clipboard access is limited.
Related issue: #672
To test, run
yarn dev
and stay within the default view and do not open the canvas in a new tab or fullscreen, you want to rely on the storybook iframe to require the permissions. Manage Clipboard access for the current site / domain in your browser to toggle permission and test with both to ensure the copy is completed irrespectively.