Skip to content

Commit

Permalink
test(module:typography): fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
hsuanxyz committed Jun 19, 2019
1 parent f5dcd81 commit f4cfd8f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
66 changes: 38 additions & 28 deletions components/core/services/nz-copy-to-clipboard.service.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { DOCUMENT } from '@angular/common';
import { Inject, Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class NzCopyToClipboardService {

constructor(@Inject(DOCUMENT) private document: Document) { }
// tslint:disable-next-line:no-any
constructor(@Inject(DOCUMENT) private document: any) {}

copy(text: string): Promise<string> {
return new Promise<string>((resolve, reject): void => {
let copyTextArea = null;
try {
// tslint:disable-next-line no-any
copyTextArea = this.document.createElement('textarea') as any;
copyTextArea.style!.all = 'unset';
copyTextArea.style.position = 'fixed';
copyTextArea.style.top = '0';
copyTextArea.style.clip = 'rect(0, 0, 0, 0)';
copyTextArea.style.whiteSpace = 'pre';
copyTextArea.style.webkitUserSelect = 'text';
copyTextArea.style!.MozUserSelect = 'text';
copyTextArea.style.msUserSelect = 'text';
copyTextArea.style.userSelect = 'text';
this.document.body.appendChild(copyTextArea);
copyTextArea.value = text;
copyTextArea.select();
return new Promise<string>(
(resolve, reject): void => {
let copyTextArea = null;
try {
// tslint:disable-next-line no-any
copyTextArea = this.document.createElement('textarea') as any;
copyTextArea.style!.all = 'unset';
copyTextArea.style.position = 'fixed';
copyTextArea.style.top = '0';
copyTextArea.style.clip = 'rect(0, 0, 0, 0)';
copyTextArea.style.whiteSpace = 'pre';
copyTextArea.style.webkitUserSelect = 'text';
copyTextArea.style!.MozUserSelect = 'text';
copyTextArea.style.msUserSelect = 'text';
copyTextArea.style.userSelect = 'text';
this.document.body.appendChild(copyTextArea);
copyTextArea.value = text;
copyTextArea.select();

const successful = this.document.execCommand('copy');
if (!successful) {
reject(text);
}
resolve(text);
} finally {
if (copyTextArea) {
this.document.body.removeChild(copyTextArea);
const successful = this.document.execCommand('copy');
if (!successful) {
reject(text);
}
resolve(text);
} finally {
if (copyTextArea) {
this.document.body.removeChild(copyTextArea);
}
}
}
});
);
}
}
1 change: 0 additions & 1 deletion components/core/services/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
export * from './nz-measure-scrollbar.service';
export * from './update-host-class.service';
export * from './nz-copy-to-clipboard.service';

2 changes: 1 addition & 1 deletion components/typography/nz-typography.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export class NzTestTypographyCopyComponent {
`
})
export class NzTestTypographyEditComponent {
@ViewChild(NzTypographyComponent) nzTypographyComponent: NzTypographyComponent;
@ViewChild(NzTypographyComponent, { static: true }) nzTypographyComponent: NzTypographyComponent;
str = 'This is an editable text.';
onChange = (text: string): void => {
this.str = text;
Expand Down

0 comments on commit f4cfd8f

Please sign in to comment.