Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
fix(filter-field): Removes FlexibleConnectedPositionStrategy, makes _…
Browse files Browse the repository at this point in the history
…viewportRuler, _platform and _overlayContainer mandatory and makes tags private.

BREAKING CHANGE: Uses DtFlexibleConnectedPositionStrategy instead. Use currentTags instead of tags.
  • Loading branch information
rowa-audil authored and ffriedl89 committed May 12, 2020
1 parent 568dc1d commit 8a0ceb0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
PositionStrategy,
ViewportRuler,
OverlayContainer,
FlexibleConnectedPositionStrategy,
} from '@angular/cdk/overlay';
import {
ChangeDetectorRef,
Expand All @@ -32,7 +31,6 @@ import {
Input,
NgZone,
OnDestroy,
Optional,
Inject,
} from '@angular/core';
import {
Expand Down Expand Up @@ -125,11 +123,8 @@ export class DtFilterFieldRangeTrigger implements OnDestroy {

/**
* Strategy that is used to position the panel.
* @breaking-change Switch to only use DtFlexibleConnectedPositionStrategy with 7.0.0
*/
private _positionStrategy:
| FlexibleConnectedPositionStrategy
| DtFlexibleConnectedPositionStrategy;
private _positionStrategy: DtFlexibleConnectedPositionStrategy;

/** Whether the component has already been destroyed */
private _componentDestroyed = false;
Expand All @@ -151,16 +146,12 @@ export class DtFilterFieldRangeTrigger implements OnDestroy {
private _elementRef: ElementRef,
private _overlay: Overlay,
private _changeDetectorRef: ChangeDetectorRef,
private _viewportRuler: ViewportRuler,
private _platform: Platform,
private _overlayContainer: OverlayContainer,
zone: NgZone,
/** @breaking-change 7.0.0 Make the _viewportRuler non-optional. */
@Optional() private _viewportRuler?: ViewportRuler,
/** @breaking-change 7.0.0 Make the _platform non-optional. */
@Optional() private _platform?: Platform,
/** @breaking-change 7.0.0 Make the _overlayContainer non-optional. */
@Optional() private _overlayContainer?: OverlayContainer,
/** @breaking-change 7.0.0 Make the _document non-optional. */
// tslint:disable-next-line:no-any
@Optional() @Inject(DOCUMENT) private _document?: any,
@Inject(DOCUMENT) private _document: any,
) {
// tslint:disable-next-line:strict-type-predicates
if (typeof window !== 'undefined') {
Expand Down Expand Up @@ -289,21 +280,13 @@ export class DtFilterFieldRangeTrigger implements OnDestroy {

/** Returns the overlay position. */
private _getOverlayPosition(): PositionStrategy {
/**
* @breaking-change Switch to only use the DtFlexibleConnectedPositionStrategy
* with 7.0.0
*/
const originalPositionStrategy =
this._viewportRuler && this._platform && this._overlayContainer
? new DtFlexibleConnectedPositionStrategy(
this._elementRef,
this._viewportRuler,
this._document,
this._platform,
this._overlayContainer,
)
: this._overlay.position().flexibleConnectedTo(this._elementRef);
this._positionStrategy = originalPositionStrategy
this._positionStrategy = new DtFlexibleConnectedPositionStrategy(
this._elementRef,
this._viewportRuler,
this._document,
this._platform,
this._overlayContainer,
)
.withFlexibleDimensions(false)
.withPush(false)
.withPositions([
Expand Down
16 changes: 7 additions & 9 deletions libs/barista-components/filter-field/src/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,19 @@ export class DtFilterField<T = any>
if (coerced !== this._disabled) {
this._disabled = coerced;

if (!this.tags || this.tags.length === 0) {
if (!this._tags || this._tags.length === 0) {
return;
}

if (this._disabled) {
this._closeFilterPanels();

this.tags.forEach((item) => {
this._tags.forEach((item) => {
this._previousTagDisabledState.set(item, item.disabled);
item.disabled = this._disabled;
});
} else {
this.tags.forEach(
this._tags.forEach(
(item) =>
(item.disabled = !!this._previousTagDisabledState.get(item)),
);
Expand Down Expand Up @@ -298,10 +298,8 @@ export class DtFilterField<T = any>
/**
* List of tags that are the visual representation for selected nodes.
* This can be used to disable certain tags or change their labeling.
* @deprecated use currentTags instead
* @breaking-change make private with 6.0.0
*/
@ViewChildren(DtFilterFieldTag) tags: QueryList<DtFilterFieldTag>;
@ViewChildren(DtFilterFieldTag) private _tags: QueryList<DtFilterFieldTag>;

/** @internal List of current tags in the filter field */
private _currentTags = new ReplaySubject<DtFilterFieldTag[]>(1);
Expand Down Expand Up @@ -535,11 +533,11 @@ export class DtFilterField<T = any>
this._handleInputChange();
});
// tslint:disable-next-line: deprecation
this.tags.changes
this._tags.changes
.pipe(startWith(null), takeUntil(this._destroy$))
.subscribe(() => {
// tslint:disable-next-line: deprecation
this._currentTags.next(this.tags.toArray());
this._currentTags.next(this._tags.toArray());
});
}

Expand Down Expand Up @@ -583,7 +581,7 @@ export class DtFilterField<T = any>
if (needleFilterValueArr) {
const filterIndex = this._findIndexForFilter(needleFilterValueArr);
// tslint:disable-next-line: deprecation
return filterIndex !== -1 ? this.tags.toArray()[filterIndex] : null;
return filterIndex !== -1 ? this._tags.toArray()[filterIndex] : null;
}
}
return null;
Expand Down

0 comments on commit 8a0ceb0

Please sign in to comment.