Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Fixed action button keyup also triggering click event #1448

Merged
merged 2 commits into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/modules/action-button/action-button.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class="sky-action-button sky-btn-default"
role="button"
(click)="buttonClicked()"
(keyup)="enterPress($event)"
(keydown.enter)="enterPress()"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only change: using keydown instead of keyup.

tabindex="0"
>
<div class="sky-action-button-icon-header-container">
Expand Down
8 changes: 5 additions & 3 deletions src/modules/action-button/action-button.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ describe('Action button component', () => {
});

it('should emit a click event on enter press', () => {

debugElement.query(By.css('.sky-action-button')).triggerEventHandler('keyup', { which: 15});
debugElement.query(By.css('.sky-action-button'))
.triggerEventHandler('keydown.escape', { });
fixture.detectChanges();
expect(cmp.buttonIsClicked).toBe(false);
debugElement.query(By.css('.sky-action-button')).triggerEventHandler('keyup', { which: 13});

debugElement.query(By.css('.sky-action-button'))
.triggerEventHandler('keydown.enter', { });
fixture.detectChanges();
expect(cmp.buttonIsClicked).toBe(true);
});
Expand Down
6 changes: 2 additions & 4 deletions src/modules/action-button/action-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export class SkyActionButtonComponent {
this.actionClick.emit();
}

public enterPress(event: KeyboardEvent) {
if (event.which === 13) {
this.actionClick.emit();
}
public enterPress() {
this.actionClick.emit();
}
}