-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: (platform) step input component defects (#3234)
* fix step-input entered value handling * fix tests
- Loading branch information
1 parent
326d085
commit f0b2f4c
Showing
11 changed files
with
157 additions
and
78 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
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
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
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
49 changes: 49 additions & 0 deletions
49
libs/platform/src/lib/components/form/step-input/step-input-action-button.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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Directive, HostListener, OnDestroy } from '@angular/core'; | ||
import { fromEvent, timer, interval, Subject } from 'rxjs'; | ||
import { switchMap, takeUntil } from 'rxjs/operators'; | ||
|
||
/** | ||
* This is a base step input directive to be used for increase/decrease buttons. | ||
*/ | ||
@Directive() | ||
export abstract class StepInputActionButton implements OnDestroy { | ||
/** @hidden */ | ||
protected _destroyed = new Subject<void>(); | ||
|
||
/** | ||
* @hidden | ||
* Indicates if action can be handled | ||
*/ | ||
abstract canHandleAction(): boolean; | ||
|
||
/** | ||
* @hidden | ||
* Step input button action handler | ||
*/ | ||
abstract runAction(): void; | ||
|
||
/** @hidden */ | ||
ngOnDestroy(): void { | ||
this._destroyed.next(); | ||
this._destroyed.complete(); | ||
} | ||
|
||
/** @hidden */ | ||
@HostListener('mousedown') | ||
click(): void { | ||
if (!this.canHandleAction()) { | ||
return; | ||
} | ||
|
||
// Run action while button is pressed | ||
timer(500) | ||
.pipe( | ||
switchMap(() => interval(40)), | ||
takeUntil(fromEvent(window, 'mouseup', { capture: true, once: true })) | ||
) | ||
.pipe(takeUntil(this._destroyed)) | ||
.subscribe(() => this.runAction()); | ||
|
||
this.runAction(); | ||
} | ||
} |
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
31 changes: 11 additions & 20 deletions
31
libs/platform/src/lib/components/form/step-input/step-input-decrement.directive.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,34 +1,25 @@ | ||
import { Directive, HostListener, SkipSelf } from '@angular/core'; | ||
import { startWith } from 'rxjs/operators'; | ||
import { Observable } from 'rxjs'; | ||
import { Directive, SkipSelf } from '@angular/core'; | ||
|
||
import { StepInputComponent } from './base.step-input'; | ||
import { streamUntilMouseUp$ } from './step-input-increment.directive'; | ||
import { StepInputActionButton } from './step-input-action-button'; | ||
|
||
/** | ||
* This Directive is used to be assigned to decrement button. | ||
*/ | ||
@Directive({ | ||
selector: '[fdpStepInputDecrement]' | ||
}) | ||
export class StepInputDecrementDirective { | ||
export class StepInputDecrementDirective extends StepInputActionButton { | ||
/** @hidden */ | ||
private _streamUntilMouseUp$: Observable<number> = streamUntilMouseUp$; | ||
|
||
/** @hidden */ | ||
constructor(@SkipSelf() private stepInput: StepInputComponent) {} | ||
|
||
/** @hidden */ | ||
@HostListener('mousedown', ['$event']) | ||
click($event: Event): void { | ||
if (!this.stepInput.canChangeValue) { | ||
return; | ||
} | ||
constructor(@SkipSelf() private stepInput: StepInputComponent) { | ||
super(); | ||
} | ||
|
||
$event.preventDefault(); | ||
canHandleAction(): boolean { | ||
return !!this.stepInput.canChangeValue; | ||
} | ||
|
||
this._streamUntilMouseUp$.pipe(startWith(null)).subscribe(() => { | ||
this.stepInput.decrease(); | ||
}); | ||
runAction(): void { | ||
this.stepInput.decrease(); | ||
} | ||
} |
Oops, something went wrong.