Skip to content

Commit 6e52023

Browse files
crisbetojelbourn
authored andcommitted
fix(overlay): flexible position strategy throwing error for empty strings (#14935)
Fixes the `FlexibleConnectedPositionStrategy` throwing an error if one of its panel classes is an empty string.
1 parent 78f55ea commit 6e52023

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/cdk/overlay/position/flexible-connected-position-strategy.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,6 +2226,19 @@ describe('FlexibleConnectedPositionStrategy', () => {
22262226
expect(overlayRef.overlayElement.classList).toContain('is-under');
22272227
});
22282228

2229+
it('should not throw if an empty string is passed in as a panel class', () => {
2230+
positionStrategy.withPositions([{
2231+
originX: 'start',
2232+
originY: 'bottom',
2233+
overlayX: 'start',
2234+
overlayY: 'top',
2235+
panelClass: ['is-below', '']
2236+
}]);
2237+
2238+
expect(() => attachOverlay({positionStrategy})).not.toThrow();
2239+
expect(overlayRef.overlayElement.classList).toContain('is-below');
2240+
});
2241+
22292242
it('should remove the panel class when detaching', () => {
22302243
positionStrategy.withPositions([{
22312244
originX: 'start',

src/cdk/overlay/position/flexible-connected-position-strategy.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
10811081
private _addPanelClasses(cssClasses: string | string[]) {
10821082
if (this._pane) {
10831083
coerceArray(cssClasses).forEach(cssClass => {
1084-
if (this._appliedPanelClasses.indexOf(cssClass) === -1) {
1084+
if (cssClass !== '' && this._appliedPanelClasses.indexOf(cssClass) === -1) {
10851085
this._appliedPanelClasses.push(cssClass);
10861086
this._pane.classList.add(cssClass);
10871087
}
@@ -1092,7 +1092,9 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
10921092
/** Clears the classes that the position strategy has applied from the overlay panel. */
10931093
private _clearPanelClasses() {
10941094
if (this._pane) {
1095-
this._appliedPanelClasses.forEach(cssClass => this._pane.classList.remove(cssClass));
1095+
this._appliedPanelClasses.forEach(cssClass => {
1096+
this._pane.classList.remove(cssClass);
1097+
});
10961098
this._appliedPanelClasses = [];
10971099
}
10981100
}

0 commit comments

Comments
 (0)