Skip to content

fix(overlay): error when trying to add/remove empty string class #14919

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
Oct 2, 2019

Conversation

crisbeto
Copy link
Member

Fixes an error being thrown if an empty string is passed as one of the values to addPanelClass or removePanelClass.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jan 22, 2019
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 22, 2019
@crisbeto crisbeto closed this Jan 22, 2019
@crisbeto crisbeto reopened this Jan 22, 2019
@mmalerba mmalerba added aaa and removed aaa labels Apr 25, 2019
@crisbeto crisbeto force-pushed the overlay-empty-class branch from 67729cc to 5f6d112 Compare June 24, 2019 21:37
@crisbeto crisbeto requested a review from jelbourn as a code owner June 24, 2019 21:37
@@ -471,7 +471,10 @@ export class OverlayRef implements PortalOutlet, OverlayReference {

coerceArray(cssClasses).forEach(cssClass => {
// We can't do a spread here, because IE doesn't support setting multiple classes.
isAdd ? classList.add(cssClass) : classList.remove(cssClass);
// Also trying to add an empty string to a DOMTokenList will throw.
if (cssClass !== '') {
Copy link
Member

Choose a reason for hiding this comment

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

Could this just be if (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.

It's super edge-case-ey, but it would technically exclude a class called false.

Copy link
Member

Choose a reason for hiding this comment

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

I don't believe that's true; the string 'false' is truthy

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean somebody passing in false as a boolean.

Copy link
Member

Choose a reason for hiding this comment

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

I would actually expect doing nothing in that case over adding a 'false' CSS class

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed.

Fixes an error being thrown if an empty string is passed as one of the values to `addPanelClass` or `removePanelClass`.
@crisbeto crisbeto force-pushed the overlay-empty-class branch from 5f6d112 to 176c4cf Compare June 25, 2019 20:00
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker labels Sep 5, 2019
@mmalerba mmalerba merged commit 5509c23 into angular:master Oct 2, 2019
mmalerba pushed a commit that referenced this pull request Oct 8, 2019
Fixes an error being thrown if an empty string is passed as one of the values to `addPanelClass` or `removePanelClass`.

(cherry picked from commit 5509c23)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants