From 87c72bd595e5efc6a60ddd90e0b0a7a215d535bc Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 25 Jul 2018 22:01:26 -0400 Subject: [PATCH] append copy textarea to modal if open --- src/services/webPlatformUtils.service.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/webPlatformUtils.service.ts b/src/services/webPlatformUtils.service.ts index f77d8040e1..842343dcdf 100644 --- a/src/services/webPlatformUtils.service.ts +++ b/src/services/webPlatformUtils.service.ts @@ -208,7 +208,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { } copyToClipboard(text: string, options?: any): void { - const doc = options ? options.doc : window.document; + const doc: Document = options ? options.doc : window.document; if ((window as any).clipboardData && (window as any).clipboardData.setData) { // IE specific code path to prevent textarea being shown while dialog is visible. (window as any).clipboardData.setData('Text', text); @@ -217,9 +217,13 @@ export class WebPlatformUtilsService implements PlatformUtilsService { textarea.textContent = text; // Prevent scrolling to bottom of page in MS Edge. textarea.style.position = 'fixed'; - doc.body.appendChild(textarea); + let copyEl = doc.body; + // For some reason copy command won't work in Firefox when modal is open if appending to body + if (this.isFirefox() && doc.body.classList.contains('modal-open')) { + copyEl = doc.body.querySelector('.modal'); + } + copyEl.appendChild(textarea); textarea.select(); - try { // Security exception may be thrown by some browsers. doc.execCommand('copy'); @@ -227,7 +231,7 @@ export class WebPlatformUtilsService implements PlatformUtilsService { // tslint:disable-next-line console.warn('Copy to clipboard failed.', e); } finally { - doc.body.removeChild(textarea); + copyEl.removeChild(textarea); } } }