This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(filter-field, autocomplete): Fixes an issue that the panels did n…
…ot react to viewport boundaries correctly. Closes #1747.
- Loading branch information
Showing
5 changed files
with
155 additions
and
26 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
34 changes: 34 additions & 0 deletions
34
libs/barista-components/core/src/common-behaviours/viewport-boundaries.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ViewportRuler } from '@angular/cdk/overlay'; | ||
import { Platform } from '@angular/cdk/platform'; | ||
import { NgZone } from '@angular/core'; | ||
import { MockNgZone } from '@dynatrace/testing/browser'; | ||
import { DtDefaultViewportResizer, DtViewportResizer } from '../viewport'; | ||
import { mixinViewportBoundaries } from './viewport-boundaries'; | ||
|
||
describe('MixinViewportBoundaries', () => { | ||
it('should augment an existing class with a _viewportBoundaries$ property', () => { | ||
const classWithDisabled = mixinViewportBoundaries(TestClass); | ||
const instance = new classWithDisabled(); | ||
|
||
// Expected the mixed-into class to have a _viewportBoundaries property | ||
expect(instance).toHaveProperty('_viewportBoundaries$'); | ||
}); | ||
|
||
it('should augment an existing class with a _destroy$ property', () => { | ||
const classWithDisabled = mixinViewportBoundaries(TestClass); | ||
const instance = new classWithDisabled(); | ||
|
||
// Expected the mixed-into class to have a _viewportBoundaries property | ||
expect(instance).toHaveProperty('_destroy$'); | ||
}); | ||
}); | ||
|
||
class TestClass { | ||
_platform = new Platform('testid'); | ||
_zone: NgZone = new MockNgZone(); | ||
_viewportRuler = new ViewportRuler(this._platform, this._zone); | ||
/** Fake instance of an DtViewportResizer. */ | ||
_viewportResizer: DtViewportResizer = new DtDefaultViewportResizer( | ||
this._viewportRuler, | ||
); | ||
} |
44 changes: 44 additions & 0 deletions
44
libs/barista-components/core/src/common-behaviours/viewport-boundaries.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,44 @@ | ||
import { EMPTY, Observable, of, Subject } from 'rxjs'; | ||
import { distinctUntilChanged, startWith, takeUntil } from 'rxjs/operators'; | ||
import { ViewportBoundaries } from '../overlay/flexible-connected-position-strategy'; | ||
import { DtViewportResizer } from '../viewport'; | ||
import { Constructor } from './constructor'; | ||
|
||
export interface HasViewportBoundaries { | ||
/** The current viewport boundaries */ | ||
_viewportBoundaries$: Observable<ViewportBoundaries>; | ||
} | ||
|
||
export interface HasDestroySubject { | ||
_destroy$: Subject<void>; | ||
} | ||
|
||
export interface HasDtViewportResizer { | ||
_viewportResizer: DtViewportResizer; | ||
} | ||
|
||
/** Mixin to augment a directive with a `viewportBoundaries$` property. */ | ||
export function mixinViewportBoundaries< | ||
T extends Constructor<HasDtViewportResizer> | ||
>( | ||
base: T, | ||
): Constructor<HasViewportBoundaries> & Constructor<HasDestroySubject> & T { | ||
return class extends base { | ||
_viewportBoundaries$: Observable<ViewportBoundaries> = EMPTY; | ||
|
||
_destroy$ = new Subject<void>(); | ||
|
||
// tslint:disable-next-line:no-any | ||
constructor(...args: any[]) { | ||
super(...args); | ||
|
||
this._viewportBoundaries$ = this._viewportResizer | ||
? this._viewportResizer.offset$.pipe( | ||
startWith({ top: 0, left: 0 }), | ||
distinctUntilChanged(), | ||
takeUntil(this._destroy$), | ||
) | ||
: of({ left: 0, top: 0 }); | ||
} | ||
}; | ||
} |
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