File tree Expand file tree Collapse file tree 1 file changed +6
-2
lines changed
packages/core/useClipboard Expand file tree Collapse file tree 1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ export function useClipboard(options: UseClipboardOptions<MaybeRefOrGetter<strin
7171 const timeout = useTimeoutFn ( ( ) => copied . value = false , copiedDuring )
7272
7373 function updateText ( ) {
74- if ( isClipboardApiSupported . value && permissionRead . value !== 'denied' ) {
74+ if ( isClipboardApiSupported . value && isAllowed ( permissionRead . value ) ) {
7575 navigator ! . clipboard . readText ( ) . then ( ( value ) => {
7676 text . value = value
7777 } )
@@ -86,7 +86,7 @@ export function useClipboard(options: UseClipboardOptions<MaybeRefOrGetter<strin
8686
8787 async function copy ( value = toValue ( source ) ) {
8888 if ( isSupported . value && value != null ) {
89- if ( isClipboardApiSupported . value && permissionWrite . value !== 'denied' )
89+ if ( isClipboardApiSupported . value && isAllowed ( permissionWrite . value ) )
9090 await navigator ! . clipboard . writeText ( value )
9191 else
9292 legacyCopy ( value )
@@ -112,6 +112,10 @@ export function useClipboard(options: UseClipboardOptions<MaybeRefOrGetter<strin
112112 return document ?. getSelection ?.( ) ?. toString ( ) ?? ''
113113 }
114114
115+ function isAllowed ( status : PermissionState | undefined ) {
116+ return status === 'granted' || status === 'prompt'
117+ }
118+
115119 return {
116120 isSupported,
117121 text : text as ComputedRef < string > ,
You can’t perform that action at this time.
0 commit comments