-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d0fb87
commit 202c39b
Showing
4 changed files
with
29 additions
and
31 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
projects/demo/src/modules/components/range/examples/import/insert-template.md
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,5 +1,5 @@ | ||
```html | ||
<tui-range max="10" [(ngModel)]="model"></tui-range> | ||
<tui-range [max]="10" [(ngModel)]="model"></tui-range> | ||
|
||
<tui-range [formControl]="testValue" [max]="10"></tui-range> | ||
``` |
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
44 changes: 20 additions & 24 deletions
44
projects/kit/components/slider/slider-readonly.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,45 +1,41 @@ | ||
import {Directive, ElementRef, HostListener, Inject, Input} from '@angular/core'; | ||
import {tuiDefaultProp, TuiDestroyService, typedFromEvent} from '@taiga-ui/cdk'; | ||
import {Observable} from 'rxjs'; | ||
import {filter, takeUntil} from 'rxjs/operators'; | ||
import {Directive, HostListener, Input} from '@angular/core'; | ||
import {tuiDefaultProp} from '@taiga-ui/cdk'; | ||
|
||
const SLIDER_INTERACTION_KEYS = [ | ||
'ArrowLeft', | ||
'ArrowRight', | ||
'ArrowUp', | ||
'ArrowDown', | ||
'Home', | ||
'End', | ||
'PageUp', | ||
'PageDown', | ||
]; | ||
|
||
/** | ||
* Native <input type='range' readonly> doesn't work. | ||
* This directive imitates this native behaviour. | ||
*/ | ||
@Directive({ | ||
selector: 'input[tuiSlider][readonly]', | ||
providers: [TuiDestroyService], | ||
}) | ||
export class TuiSliderReadonlyDirective { | ||
private readonly ARROWS = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown']; | ||
|
||
@Input() | ||
@tuiDefaultProp() | ||
readonly: '' | boolean = true; | ||
|
||
constructor( | ||
@Inject(ElementRef) {nativeElement}: ElementRef, | ||
@Inject(TuiDestroyService) destroy$: Observable<unknown>, | ||
) { | ||
/* @HostListener('keydown.arrowLeft') doesn't invoke function if some system key (ctrl, control, meta) was pressed */ | ||
typedFromEvent(nativeElement, 'keydown') | ||
.pipe( | ||
filter(({key}) => this.ARROWS.includes(key)), | ||
takeUntil(destroy$), | ||
) | ||
.subscribe(event => this.preventEvent(event)); | ||
} | ||
|
||
@HostListener('mousedown', ['$event']) | ||
@HostListener('touchstart', ['$event']) | ||
@HostListener('keydown.home', ['$event']) | ||
@HostListener('keydown.end', ['$event']) | ||
@HostListener('keydown.pageUp', ['$event']) | ||
@HostListener('keydown.pageDown', ['$event']) | ||
preventEvent(event: Event) { | ||
if (this.readonly === '' || this.readonly) { | ||
event.preventDefault(); | ||
} | ||
} | ||
|
||
@HostListener('keydown', ['$event']) | ||
preventKeyboardInteraction(event: KeyboardEvent) { | ||
if (SLIDER_INTERACTION_KEYS.includes(event.key)) { | ||
this.preventEvent(event); | ||
} | ||
} | ||
} |