@@ -9,13 +9,14 @@ import { IGX_DROPDOWN_BASE, IgxDropDownItemComponent, ISelectionEventArgs } from
99import { IgxHintDirective , IgxInputState , IgxLabelDirective , IgxPrefixDirective , IgxSuffixDirective } from '../../../input-group/src/public_api' ;
1010import { IgxSelectComponent , IgxSelectFooterDirective , IgxSelectHeaderDirective } from './select.component' ;
1111import { IgxSelectItemComponent } from './select-item.component' ;
12- import { HorizontalAlignment , VerticalAlignment , ConnectedPositioningStrategy , AbsoluteScrollStrategy , IgxSelectionAPIService } from 'igniteui-angular/core' ;
12+ import { HorizontalAlignment , VerticalAlignment , ConnectedPositioningStrategy , AbsoluteScrollStrategy , AutoPositionStrategy , IgxSelectionAPIService } from 'igniteui-angular/core' ;
1313import { UIInteractions } from '../../../test-utils/ui-interactions.spec' ;
1414import { IgxButtonDirective } from '../../../directives/src/directives/button/button.directive' ;
1515import { IgxIconComponent } from 'igniteui-angular/icon' ;
1616import { IgxSelectGroupComponent } from './select-group.component' ;
1717import { IgxDropDownItemBaseDirective } from '../../../drop-down/src/drop-down/drop-down-item.base' ;
1818import { addScrollDivToElement } from 'igniteui-angular/core/src/services/overlay/overlay.spec' ;
19+ import { IgxSelectOverlapPositionStrategy } from './select-overlap-positioning-strategy' ;
1920
2021const CSS_CLASS_INPUT_GROUP = 'igx-input-group' ;
2122const CSS_CLASS_INPUT = 'igx-input-group__input' ;
@@ -191,6 +192,39 @@ describe('igxSelect', () => {
191192 expect ( select . disabled ) . toBeTruthy ( ) ;
192193 } ) ;
193194
195+ it ( 'should use AutoPositionStrategy as the default position strategy' , ( ) => {
196+ // The public overlaySettings input is undefined by default
197+ expect ( select . overlaySettings ) . toBeUndefined ( ) ;
198+ // The internal _overlayDefaults should use AutoPositionStrategy
199+ expect ( ( select as any ) . _overlayDefaults . positionStrategy ) . toBeInstanceOf ( AutoPositionStrategy ) ;
200+ // The merged settings should target the input-group bundle element, not the raw input
201+ const merged = ( select as any ) . getMergedOverlaySettings ( ) ;
202+ const bundleElement = select . inputGroup . element . nativeElement . querySelector ( '.igx-input-group__bundle' ) ;
203+ expect ( merged . target ) . toBe ( bundleElement ) ;
204+ expect ( merged . target ) . not . toBe ( select . getEditElement ( ) ) ;
205+ } ) ;
206+
207+ it ( 'should allow opt-in to IgxSelectOverlapPositionStrategy via overlaySettings' , fakeAsync ( ( ) => {
208+ const overlapStrategy = new IgxSelectOverlapPositionStrategy ( select ) ;
209+ select . overlaySettings = { positionStrategy : overlapStrategy } ;
210+ expect ( select . overlaySettings . positionStrategy ) . toBeInstanceOf ( IgxSelectOverlapPositionStrategy ) ;
211+ expect ( ( select . overlaySettings . positionStrategy as IgxSelectOverlapPositionStrategy ) . isItemOverlapPositioning ) . toBeTrue ( ) ;
212+ // The merged settings should switch the target to the raw input element
213+ const merged = ( select as any ) . getMergedOverlaySettings ( ) ;
214+ expect ( merged . target ) . toBe ( select . getEditElement ( ) ) ;
215+
216+ // The select should still open correctly when using the overlap strategy
217+ select . open ( ) ;
218+ tick ( ) ;
219+ fixture . detectChanges ( ) ;
220+ expect ( select . collapsed ) . toBeFalsy ( ) ;
221+
222+ select . close ( ) ;
223+ tick ( ) ;
224+ fixture . detectChanges ( ) ;
225+ expect ( select . collapsed ) . toBeTruthy ( ) ;
226+ } ) ) ;
227+
194228 it ( 'should open dropdown on input click' , ( ) => {
195229 const inputGroup = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT_GROUP ) ) ;
196230 expect ( select . collapsed ) . toBeTruthy ( ) ;
@@ -287,6 +321,7 @@ describe('igxSelect', () => {
287321
288322 it ( 'should properly emit opening/closing events on input click' , fakeAsync ( ( ) => {
289323 const inputGroup = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT_GROUP ) ) ;
324+ const inputBundle = inputGroup . nativeElement . querySelector ( '.igx-input-group__bundle' ) as HTMLElement ;
290325 expect ( select ) . toBeTruthy ( ) ;
291326
292327 spyOn ( select . opening , 'emit' ) ;
@@ -297,19 +332,19 @@ describe('igxSelect', () => {
297332 spyOn ( select , 'open' ) . and . callThrough ( ) ;
298333 spyOn ( select , 'close' ) . and . callThrough ( ) ;
299334
300- inputGroup . nativeElement . click ( ) ;
335+ inputBundle . click ( ) ;
301336 tick ( ) ;
302337 fixture . detectChanges ( ) ;
303338 verifyOpenCloseEvents ( 1 , 0 , 1 ) ;
304339
305- inputGroup . nativeElement . click ( ) ;
340+ inputBundle . click ( ) ;
306341 tick ( ) ;
307342 fixture . detectChanges ( ) ;
308343 verifyOpenCloseEvents ( 1 , 1 , 2 ) ;
309344
310345 select . disabled = true ;
311346 fixture . detectChanges ( ) ;
312- inputGroup . nativeElement . click ( ) ;
347+ inputBundle . click ( ) ;
313348 tick ( ) ;
314349 fixture . detectChanges ( ) ;
315350
@@ -2220,6 +2255,7 @@ describe('igxSelect', () => {
22202255 } ) ) ;
22212256 } ) ;
22222257 describe ( 'Positioning tests: ' , ( ) => {
2258+ describe ( 'IgxSelectOverlapPositionStrategy positioning tests: ' , ( ) => {
22232259 const defaultWindowToListOffset = 16 ;
22242260 const defaultItemLeftPadding = 24 ;
22252261 const defaultItemTopPadding = 0 ;
@@ -2258,6 +2294,7 @@ describe('igxSelect', () => {
22582294 fixture = TestBed . createComponent ( IgxSelectMiddleComponent ) ;
22592295 select = fixture . componentInstance . select ;
22602296 fixture . detectChanges ( ) ;
2297+ select . overlaySettings = { positionStrategy : new IgxSelectOverlapPositionStrategy ( select ) } ;
22612298 inputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
22622299 selectList = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_DROPDOWN_LIST_SCROLL ) ) ;
22632300 addScrollDivToElement ( fixture . nativeElement ) ;
@@ -2358,6 +2395,7 @@ describe('igxSelect', () => {
23582395 fixture = TestBed . createComponent ( IgxSelectTopComponent ) ;
23592396 select = fixture . componentInstance . select ;
23602397 fixture . detectChanges ( ) ;
2398+ select . overlaySettings = { positionStrategy : new IgxSelectOverlapPositionStrategy ( select ) } ;
23612399 inputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
23622400 selectList = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_DROPDOWN_LIST_SCROLL ) ) ;
23632401 } ) ;
@@ -2407,6 +2445,7 @@ describe('igxSelect', () => {
24072445 fixture = TestBed . createComponent ( IgxSelectBottomComponent ) ;
24082446 select = fixture . componentInstance . select ;
24092447 fixture . detectChanges ( ) ;
2448+ select . overlaySettings = { positionStrategy : new IgxSelectOverlapPositionStrategy ( select ) } ;
24102449 inputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
24112450 selectList = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_DROPDOWN_LIST_SCROLL ) ) ;
24122451 } ) ;
@@ -2452,6 +2491,7 @@ describe('igxSelect', () => {
24522491 fixture = TestBed . createComponent ( IgxSelectMiddleComponent ) ;
24532492 fixture . detectChanges ( ) ;
24542493 select = fixture . componentInstance . select ;
2494+ select . overlaySettings = { positionStrategy : new IgxSelectOverlapPositionStrategy ( select ) } ;
24552495 inputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
24562496 selectList = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_DROPDOWN_LIST_SCROLL ) ) ;
24572497 addScrollDivToElement ( fixture . nativeElement ) ;
@@ -2557,6 +2597,30 @@ describe('igxSelect', () => {
25572597 verifyListPositioning ( ) ;
25582598 } ) ) ;
25592599 } ) ;
2600+ } ) ; // end IgxSelectOverlapPositionStrategy positioning tests
2601+
2602+ describe ( 'AutoPositionStrategy positioning tests: ' , ( ) => {
2603+ beforeEach ( ( ) => {
2604+ fixture = TestBed . createComponent ( IgxSelectSimpleComponent ) ;
2605+ select = fixture . componentInstance . select ;
2606+ fixture . detectChanges ( ) ;
2607+ inputElement = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_INPUT ) ) ;
2608+ selectList = fixture . debugElement . query ( By . css ( '.' + CSS_CLASS_DROPDOWN_LIST_SCROLL ) ) ;
2609+ } ) ;
2610+
2611+ it ( 'should open and close correctly using the default AutoPositionStrategy' , fakeAsync ( ( ) => {
2612+ expect ( ( select as any ) . _overlayDefaults . positionStrategy ) . toBeInstanceOf ( AutoPositionStrategy ) ;
2613+ select . toggle ( ) ;
2614+ tick ( ) ;
2615+ fixture . detectChanges ( ) ;
2616+ expect ( select . collapsed ) . toBeFalsy ( ) ;
2617+
2618+ select . toggle ( ) ;
2619+ tick ( ) ;
2620+ fixture . detectChanges ( ) ;
2621+ expect ( select . collapsed ) . toBeTruthy ( ) ;
2622+ } ) ) ;
2623+ } ) ;
25602624 } ) ;
25612625 describe ( 'EditorProvider' , ( ) => {
25622626 beforeEach ( ( ) => {
0 commit comments