-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(cdk-experimental/clipboard): add better support for iOS devices, preliminary documentations #16830
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
feat(cdk-experimental/clipboard): add better support for iOS devices, preliminary documentations #16830
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
**Warning: this component is still experimental. It may have bugs and the API may change at any | ||
time** | ||
|
||
The scrolling package provides helpers for working with the system clipboard. | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## The `Clipboard` service | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The `Clipboard` service copies text to the | ||
user's clipboard. It has two methods, `copy` and `beginCopy`. For cases where | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "For cases where you are copying a relatively small amount of text," Is there any quantitative guidance here? A certain number of characters? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know of any - it very much depends on the user's computer specs. We could do some research about this and update the section before release. |
||
you are copying a relatively small amount of text, you can just call `copy` to | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
place it on the clipboard. | ||
|
||
```typescript | ||
class MyCopier { | ||
constructor(private clipboard: Clipboard) {} | ||
|
||
copy() { | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.clipboard.copy('Hello clipboard!'); | ||
} | ||
} | ||
``` | ||
|
||
However, for a large amount of text the browser needs time to load it into a | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hidden textarea where it can be copied. Just calling `copy` directly may fail in | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this case, so you can pre-load the text by calling `beginCopy`. This method | ||
returns a `PendingCopy` object that has a `copy` method to finish copying the | ||
text that was buffered. Please note, if you call `beginCopy` it is up to you to | ||
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
xkxx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
clean up the `PendingCopy` object by calling `destroy` on it after you are | ||
finished. | ||
|
||
```typescript | ||
class MyCopier { | ||
hugeText: string; | ||
|
||
constructor(private clipboard: Clipboard) {} | ||
|
||
copy() { | ||
const pending = this.clipboard.beginCopy(this.hugeText); | ||
let remainingAttempts = 3; | ||
const attempt = () => { | ||
const result = pending.copy(); | ||
if (!result && --remainingAttempts) { | ||
setTimeout(attempt); | ||
} else { | ||
// Remember to destroy when you're done! | ||
pending.destroy(); | ||
} | ||
} | ||
setTimeout(attempt); | ||
} | ||
} | ||
``` | ||
|
||
## The `cdkCopyToClipboard` directive | ||
|
||
The `cdkCopyToClipboard` directive can be used to easily add copy-on-click | ||
functionality to an existing element. The directive selector doubles as an | ||
`@Input()` for the text to be copied. | ||
|
||
```html | ||
<img src="doge.jpg" alt="Doge" [xapCopyToClipboard]="getDogeSpeakText()"> | ||
``` |
Uh oh!
There was an error while loading. Please reload this page.