Skip to content

Commit

Permalink
fix: do not throw when overlayClass is set to empty string (#7386) (#…
Browse files Browse the repository at this point in the history
…7388)

Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
  • Loading branch information
vaadin-bot and web-padawan committed May 7, 2024
1 parent 3cbb185 commit b5a6968
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/component-base/src/overlay-class-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const OverlayClassMixin = (superclass) =>
}

// Add new classes based on the overlayClass
const classesToAdd = typeof overlayClass === 'string' ? overlayClass.split(' ') : [];
const classesToAdd = typeof overlayClass === 'string' ? overlayClass.split(' ').filter(Boolean) : [];
if (classesToAdd.length > 0) {
classList.add(...classesToAdd);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/component-base/test/overlay-class-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ const runTests = (defineHelper, baseMixin) => {
expect(overlay.classList.contains('foo')).to.be.true;
expect(overlay.classList.contains('bar')).to.be.false;
});

it('should remove class names when setting empty string', async () => {
element.overlayClass = 'foo bar';
await nextUpdate(element);

element.overlayClass = '';
await nextUpdate(element);

expect(overlay.classList.contains('foo')).to.be.false;
expect(overlay.classList.contains('bar')).to.be.false;
});

it('should remove class names when setting whitespace string', async () => {
element.overlayClass = 'foo bar';
await nextUpdate(element);

element.overlayClass = ' ';
await nextUpdate(element);

expect(overlay.classList.contains('foo')).to.be.false;
expect(overlay.classList.contains('bar')).to.be.false;
});
});

describe('custom classes', () => {
Expand Down

0 comments on commit b5a6968

Please sign in to comment.