Skip to content

Commit

Permalink
Fixed click listener on button
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremythuff committed May 13, 2021
1 parent d635577 commit 284a87b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<button-wrapper #animationRoot>
<button *ngIf="!href"
[attr.id]="htmlId"
class="wvr-components wvr-button btn {{btnType!=='link' ? 'btn-'+themeVariant : ''}}"
[type]="btnType"
[ngClass]="{
Expand All @@ -12,6 +13,7 @@
<ng-container *ngTemplateOutlet="content"></ng-container>
</button>
<a *ngIf="href"
[attr.id]="htmlId"
class="wvr-components wvr-button btn {{btnType!=='link' ? 'btn-'+themeVariant : ''}}"
[href]="href"
[ngClass]="{
Expand Down
51 changes: 27 additions & 24 deletions projects/wvr-elements/src/lib/wvr-button/wvr-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { WvrBaseComponent } from '../shared/wvr-base.component';
})
export class WvrButtonComponent extends WvrBaseComponent {

htmlId = `wvr-button-${this.id}`;

/** Used to define the class type for button component. */
@Input() themeVariant: ThemeVariantName = 'primary';

Expand Down Expand Up @@ -138,30 +140,31 @@ export class WvrButtonComponent extends WvrBaseComponent {
super(injector);
}

@HostListener('click', ['$event']) click($event: MouseEvent): void {

if (this._dispatchActions) {
this._dispatchActions.forEach(actionAndProp => {
this.store.dispatch(actionAndProp.action(
actionAndProp.props
));
});
} else if (this._action) {
this._actionProps ?
this.store.dispatch(this._action(
this._actionProps
)) :
this.store.dispatch(this._action());
}

if (this.emitEvent) {
this.eRef.nativeElement.dispatchEvent(new CustomEvent(this.emitEvent, {
bubbles: true,
detail: {
data: (this.eRef.nativeElement as HTMLElement).dataset,
button: this
}
}));
@HostListener('document:click', ['$event']) click($event: MouseEvent): void {
if (($event.target as HTMLElement).id === this.htmlId) {
if (this._dispatchActions) {
this._dispatchActions.forEach(actionAndProp => {
this.store.dispatch(actionAndProp.action(
actionAndProp.props
));
});
} else if (this._action) {
this._actionProps ?
this.store.dispatch(this._action(
this._actionProps
)) :
this.store.dispatch(this._action());
}

if (this.emitEvent) {
this.eRef.nativeElement.dispatchEvent(new CustomEvent(this.emitEvent, {
bubbles: true,
detail: {
data: (this.eRef.nativeElement as HTMLElement).dataset,
button: this
}
}));
}
}
}

Expand Down

0 comments on commit 284a87b

Please sign in to comment.