-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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 to Clipboard button action #15689
Conversation
QA Wolf here! As you write new code it's important that your test coverage is keeping up. |
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.
LGTM - nice demo!
...er/src/components/design/settings/controls/ButtonActionEditor/actions/CopyToClipboard.svelte
Show resolved
Hide resolved
|
||
navigator.clipboard | ||
.writeText(textToCopy) | ||
.then(() => { |
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.
our preference for things like this would be to make this an async function, e.g. async action => { ...
and then use await,
try {
await navigator.clipboard.writeText(textToCopy)
if (showNotification) {
const message = notificationMessage || "Copied to clipboard"
notificationStore.actions.success(message, true, 3000)
}
return { copied: textToCopy }
} catch (err) {
console.error("Failed to copy text: ", err)
notificationStore.actions.error("Failed to copy to clipboard")
}
This means that the further button actions in the sequence will wait for the copy to clipboard to complete before moving on.
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.
thanks @mike12345567, it is much nicer right enough
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.
LGTM - one comment on handling promises, but otherwise looks good!
Description
As demoed earlier I have added a simple copy to clipboard action which does what it says on the tin on an on click/on change action. There's the option to show a notification after the value is copied. You can access the copied value in future steps using the binding
{{ Action X.Copied text }}
Screenshots
Launchcontrol
Add a Copy to Clipboard on click action