Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(web/clipboard): allow writing empty string #2371

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/web/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class ClipboardPluginWeb extends WebPlugin implements ClipboardPlugin {
return Promise.reject('Clipboard API not available in this browser');
}

if (options.string || options.url) {
await navigator.clipboard.writeText(options.string || options.url);
if (options.string !== undefined || options.url) {
await navigator.clipboard.writeText(options.string !== undefined ? options.string : options.url);
} else if (options.image) {
return Promise.reject('Setting images not supported on the web');
}
Expand Down
6 changes: 6 additions & 0 deletions example/src/pages/clipboard/clipboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<button (click)="clipboardSetString()" ion-button color="primary">
Copy String
</button>
<button (click)="clipboardSetEmptyString()" ion-button color="primary">
Copy Empty String
</button>
<button (click)="clipboardSetURL()" ion-button color="primary">
Copy URL
</button>
Expand All @@ -31,6 +34,9 @@
<button (click)="clipboardGetString()" ion-button color="primary">
Paste String
</button>
<button (click)="clipboardGetEmptyString()" ion-button color="primary">
Paste Empty String
</button>
<button (click)="clipboardGetURL()" ion-button color="primary">
Paste URL
</button>
Expand Down
13 changes: 13 additions & 0 deletions example/src/pages/clipboard/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ export class ClipboardPage {
console.log('Got string from clipboard:', str.value);
}

clipboardSetEmptyString() {
Plugins.Clipboard.write({
string: ""
});
}

async clipboardGetEmptyString() {
let str = await Plugins.Clipboard.read({
type: "string"
});
console.log('Got string from clipboard:', str.value);
}

clipboardSetURL() {
Plugins.Clipboard.write({
url: "http://google.com/"
Expand Down