-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(button): prevent click bindings from firing on disabled anchor bu…
…ttons (#963) Co-authored-by: Alexander Sawtschuk <[email protected]>
- Loading branch information
1 parent
2928f7a
commit 3d2ef2d
Showing
10 changed files
with
143 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import { FocusMonitor } from '@angular/cdk/a11y'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, HostListener } from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { NxTriggerButton } from '@aposin/ng-aquila/overlay'; | ||
|
||
import { NxButtonComponent } from './button.component'; | ||
import { NxAnchorButtonBase } from './button-base'; | ||
|
||
@Component({ | ||
templateUrl: './button.html', | ||
styleUrls: ['button.scss'], | ||
selector: 'a[nxButton]', | ||
inputs: ['classNames:nxButton'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
inputs: ['classNames:nxButton'], | ||
providers: [{ provide: NxTriggerButton, useExisting: NxAnchorButtonComponent }], | ||
host: { | ||
class: 'nx-button', | ||
}, | ||
}) | ||
export class NxAnchorButtonComponent extends NxButtonComponent { | ||
/** @docs-private */ | ||
@HostListener('click', ['$event']) | ||
_checkEventsDisabled(event: Event) { | ||
if (this.disabled) { | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
} | ||
} | ||
|
||
constructor(_cdr: ChangeDetectorRef, elementRef: ElementRef, focusMonitor: FocusMonitor) { | ||
super(_cdr, elementRef, focusMonitor); | ||
} | ||
} | ||
export class NxAnchorButtonComponent extends NxAnchorButtonBase {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
projects/ng-aquila/src/button/anchor-icon-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import { FocusMonitor } from '@angular/cdk/a11y'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, HostListener } from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { NxTriggerButton } from '@aposin/ng-aquila/overlay'; | ||
|
||
import { NxIconButtonComponent } from './icon-button.component'; | ||
import { NxAnchorButtonBase } from './button-base'; | ||
|
||
@Component({ | ||
templateUrl: './button.html', | ||
styleUrls: ['button.scss'], | ||
selector: 'a[nxIconButton]', | ||
inputs: ['classNames:nxIconButton'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
inputs: ['classNames:nxIconButton'], | ||
providers: [{ provide: NxTriggerButton, useExisting: NxAnchorIconButtonComponent }], | ||
host: { | ||
class: 'nx-icon-button', | ||
}, | ||
}) | ||
export class NxAnchorIconButtonComponent extends NxIconButtonComponent { | ||
/** @docs-private */ | ||
@HostListener('click', ['$event']) | ||
_checkEventsDisabled(event: Event) { | ||
if (this.disabled) { | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
} | ||
} | ||
|
||
constructor(_cdr: ChangeDetectorRef, elementRef: ElementRef, focusMonitor: FocusMonitor) { | ||
super(_cdr, elementRef, focusMonitor); | ||
} | ||
} | ||
export class NxAnchorIconButtonComponent extends NxAnchorButtonBase {} |
75 changes: 40 additions & 35 deletions
75
projects/ng-aquila/src/button/anchor-plain-button.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 7 additions & 19 deletions
26
projects/ng-aquila/src/button/anchor-plain-button.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import { FocusMonitor } from '@angular/cdk/a11y'; | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, HostListener } from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { NxTriggerButton } from '@aposin/ng-aquila/overlay'; | ||
|
||
import { NxPlainButtonComponent } from './plain-button.component'; | ||
import { NxAnchorButtonBase } from './button-base'; | ||
|
||
@Component({ | ||
templateUrl: './plain-button.component.html', | ||
styleUrls: ['plain-button.component.scss'], | ||
selector: 'a[nxPlainButton]', | ||
inputs: ['classNames:nxPlainButton'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
inputs: ['classNames:nxPlainButton'], | ||
providers: [{ provide: NxTriggerButton, useExisting: NxAnchorPlainButtonComponent }], | ||
host: { | ||
class: 'nx-plain-button', | ||
}, | ||
}) | ||
export class NxAnchorPlainButtonComponent extends NxPlainButtonComponent { | ||
/** @docs-private */ | ||
@HostListener('click', ['$event']) | ||
_checkEventsDisabled(event: Event) { | ||
if (this.disabled) { | ||
event.preventDefault(); | ||
event.stopImmediatePropagation(); | ||
} | ||
} | ||
|
||
constructor(_cdr: ChangeDetectorRef, elementRef: ElementRef, focusMonitor: FocusMonitor) { | ||
super(_cdr, elementRef, focusMonitor); | ||
} | ||
} | ||
export class NxAnchorPlainButtonComponent extends NxAnchorButtonBase {} |
Oops, something went wrong.