1- import { Component , ViewChild } from '@angular/core' ;
1+ import { Component , Input , ViewChild } from '@angular/core' ;
22import { ComponentFixture , fakeAsync , TestBed , tick , waitForAsync } from '@angular/core/testing' ;
33import { FormsModule , ReactiveFormsModule , UntypedFormControl } from '@angular/forms' ;
44import { By , HammerModule } from '@angular/platform-browser' ;
@@ -1753,6 +1753,10 @@ describe('IgxSlider', () => {
17531753 fakeDoc . documentElement . dir = 'rtl' ;
17541754 } ) ;
17551755
1756+ afterEach ( ( ) => {
1757+ fakeDoc . documentElement . dir = 'ltr' ;
1758+ } ) ;
1759+
17561760 it ( 'should reflect on the right instead of the left css property of the slider handlers' , ( ) => {
17571761 const fix = TestBed . createComponent ( SliderRtlComponent ) ;
17581762 fix . detectChanges ( ) ;
@@ -1809,6 +1813,40 @@ describe('IgxSlider', () => {
18091813 fixture . detectChanges ( ) ;
18101814 expect ( slider . value ) . toBe ( formControl . value ) ;
18111815 } ) ;
1816+
1817+ it ( 'Should respect the ngModelOptions updateOn: blur' , fakeAsync ( ( ) => {
1818+ const fixture = TestBed . createComponent ( SliderTemplateFormComponent ) ;
1819+ fixture . componentInstance . updateOn = 'blur' ;
1820+ fixture . componentInstance . value = 0 ;
1821+ fixture . detectChanges ( ) ;
1822+
1823+ const slider = fixture . componentInstance . slider ;
1824+
1825+ const thumbEl = fixture . debugElement . query ( By . css ( THUMB_TAG ) ) . nativeElement ;
1826+ const { x : sliderX , width : sliderWidth } = thumbEl . getBoundingClientRect ( ) ;
1827+ const startX = sliderX + sliderWidth / 2 ;
1828+
1829+ thumbEl . dispatchEvent ( new Event ( 'focus' ) ) ;
1830+ fixture . detectChanges ( ) ;
1831+
1832+ ( slider as any ) . onPointerDown ( new PointerEvent ( 'pointerdown' , { pointerId : 1 , clientX : startX } ) ) ;
1833+ fixture . detectChanges ( ) ;
1834+ tick ( ) ;
1835+
1836+ ( slider as any ) . onPointerMove ( new PointerEvent ( 'pointermove' , { pointerId : 1 , clientX : startX + 150 } ) ) ;
1837+ fixture . detectChanges ( ) ;
1838+ tick ( ) ;
1839+
1840+ const activeThumb = fixture . debugElement . query ( By . css ( THUMB_TO_PRESSED_CLASS ) ) ;
1841+ expect ( activeThumb ) . not . toBeNull ( ) ;
1842+ expect ( fixture . componentInstance . value ) . not . toBeGreaterThan ( 0 ) ;
1843+
1844+ thumbEl . dispatchEvent ( new Event ( 'blur' ) ) ;
1845+ fixture . detectChanges ( ) ;
1846+ tick ( ) ;
1847+
1848+ expect ( fixture . componentInstance . value ) . toBeGreaterThan ( 0 ) ;
1849+ } ) ) ;
18121850 } ) ;
18131851
18141852
@@ -1984,7 +2022,7 @@ class RangeSliderWithCustomTemplateComponent {
19842022@Component ( {
19852023 template : `
19862024 <form #form="ngForm">
1987- <igx-slider [(ngModel)]="value" name="amount"></igx-slider>
2025+ <igx-slider [(ngModel)]="value" name="amount" [ngModelOptions]="{ updateOn: updateOn}" ></igx-slider>
19882026 </form>
19892027 ` ,
19902028 standalone : true ,
@@ -1993,6 +2031,8 @@ class RangeSliderWithCustomTemplateComponent {
19932031export class SliderTemplateFormComponent {
19942032 @ViewChild ( IgxSliderComponent , { read : IgxSliderComponent , static : true } ) public slider : IgxSliderComponent ;
19952033
2034+ @Input ( ) public updateOn : 'change' | 'blur' | 'submit' = 'change' ;
2035+
19962036 public value = 10 ;
19972037}
19982038
0 commit comments