Skip to content

fix(overlay): flexible position strategy throwing error for empty strings #14935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2168,6 +2168,19 @@ describe('FlexibleConnectedPositionStrategy', () => {
expect(overlayRef.overlayElement.classList).toContain('is-under');
});

it('should not throw if an empty string is passed in as a panel class', () => {
positionStrategy.withPositions([{
originX: 'start',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top',
panelClass: ['is-below', '']
}]);

expect(() => attachOverlay({positionStrategy})).not.toThrow();
expect(overlayRef.overlayElement.classList).toContain('is-below');
});

it('should remove the panel class when detaching', () => {
positionStrategy.withPositions([{
originX: 'start',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
private _addPanelClasses(cssClasses: string | string[]) {
if (this._pane) {
coerceArray(cssClasses).forEach(cssClass => {
if (this._appliedPanelClasses.indexOf(cssClass) === -1) {
if (cssClass !== '' && this._appliedPanelClasses.indexOf(cssClass) === -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to do cssClass &&?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory somebody could set the class to something like null which is technically an accepted value in DOMTokenList ¯\_(ツ)_/¯

this._appliedPanelClasses.push(cssClass);
this._pane.classList.add(cssClass);
}
Expand All @@ -1092,7 +1092,9 @@ export class FlexibleConnectedPositionStrategy implements PositionStrategy {
/** Clears the classes that the position strategy has applied from the overlay panel. */
private _clearPanelClasses() {
if (this._pane) {
this._appliedPanelClasses.forEach(cssClass => this._pane.classList.remove(cssClass));
this._appliedPanelClasses.forEach(cssClass => {
this._pane.classList.remove(cssClass);
});
this._appliedPanelClasses = [];
}
}
Expand Down