Revert "[ACS-4051] Copy to clipboard button is now accessible through the keyboard enter earlier which was only accessible through mouse click (#8165)" (#8224)

This reverts commit 11c3a02acc.
This commit is contained in:
Jatin Chugh
2023-02-02 18:23:25 +05:30
committed by GitHub
parent e8a3d109d4
commit 3f8293b64c
2 changed files with 8 additions and 25 deletions

View File

@@ -64,15 +64,6 @@ describe('ClipboardDirective', () => {
expect(clipboardService.copyToClipboard).toHaveBeenCalled();
});
it('should notify copy target value on keydown event', () => {
spyOn(clipboardService, 'copyToClipboard');
fixture.nativeElement.querySelector('input').value = 'some value';
fixture.nativeElement.querySelector('button').dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
expect(clipboardService.copyToClipboard).toHaveBeenCalled();
});
});
describe('CopyClipboardDirective', () => {
@@ -137,16 +128,6 @@ describe('CopyClipboardDirective', () => {
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
}));
it('should copy the content of element on keydown event', fakeAsync(() => {
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
fixture.detectChanges();
spyOn(navigator.clipboard, 'writeText');
spanHTMLElement.dispatchEvent(new KeyboardEvent('keydown', {code: 'Enter', key: 'Enter'}));
tick();
fixture.detectChanges();
expect(navigator.clipboard.writeText).toHaveBeenCalledWith('text to copy');
}));
it('should not copy the content of element when click it', fakeAsync(() => {
const spanHTMLElement = element.querySelector<HTMLInputElement>('span');
fixture.detectChanges();

View File

@@ -40,6 +40,13 @@ export class ClipboardDirective {
public viewContainerRef: ViewContainerRef,
private resolver: ComponentFactoryResolver) {}
@HostListener('click', ['$event'])
handleClickEvent(event: MouseEvent) {
event.preventDefault();
event.stopPropagation();
this.copyToClipboard();
}
@HostListener('mouseenter')
showTooltip() {
if (this.placeholder) {
@@ -54,12 +61,7 @@ export class ClipboardDirective {
this.viewContainerRef.remove();
}
@HostListener('click', ['$event'])
@HostListener('keydown.enter', ['$event'])
copyToClipboard(event: MouseEvent | KeyboardEvent) {
event.preventDefault();
event.stopPropagation();
private copyToClipboard() {
const isValidTarget = this.clipboardService.isTargetValid(this.target);
if (isValidTarget) {