File tree Expand file tree Collapse file tree 5 files changed +26
-3
lines changed
Expand file tree Collapse file tree 5 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 55 */
66import { html , LitElement } from 'lit' ;
77import { defineCustomElement } from '@vaadin/component-base/src/define.js' ;
8+ import { isEmptyTextNode } from '@vaadin/component-base/src/dom-utils.js' ;
89import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js' ;
910import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js' ;
1011import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js' ;
@@ -157,13 +158,19 @@ class Card extends ElementMixin(ThemableMixin(PolylitMixin(LumoInjectionMixin(Li
157158 ) ;
158159 this . toggleAttribute ( '_hp' , this . querySelector ( ':scope > [slot="header-prefix"]' ) ) ;
159160 this . toggleAttribute ( '_hs' , this . querySelector ( ':scope > [slot="header-suffix"]' ) ) ;
160- this . toggleAttribute ( '_c' , this . querySelector ( ':scope > :not([slot])' ) ) ;
161+ this . toggleAttribute ( '_c' , this . __hasContent ( ) ) ;
161162 this . toggleAttribute ( '_f' , this . querySelector ( ':scope > [slot="footer"]' ) ) ;
162163 if ( this . __getCustomTitleElement ( ) ) {
163164 this . __clearStringTitle ( ) ;
164165 }
165166 }
166167
168+ /** @private */
169+ __hasContent ( ) {
170+ const slot = this . shadowRoot . querySelector ( 'slot:not([name])' ) ;
171+ return slot . assignedNodes ( { flatten : true } ) . filter ( ( node ) => ! isEmptyTextNode ( node ) ) . length > 0 ;
172+ }
173+
167174 /** @private */
168175 __clearStringTitle ( ) {
169176 const stringTitleElement = this . __getStringTitleElement ( ) ;
Original file line number Diff line number Diff line change @@ -138,6 +138,16 @@ snapshots["vaadin-card host content"] =
138138` ;
139139/* end snapshot vaadin-card host content */
140140
141+ snapshots [ "vaadin-card host text content" ] =
142+ `<vaadin-card
143+ _c=""
144+ role="region"
145+ >
146+ Text content
147+ </vaadin-card>
148+ ` ;
149+ /* end snapshot vaadin-card host text content */
150+
141151snapshots [ "vaadin-card host footer" ] =
142152`<vaadin-card
143153 _f=""
Original file line number Diff line number Diff line change @@ -109,6 +109,12 @@ describe('vaadin-card', () => {
109109 await expect ( card ) . dom . to . equalSnapshot ( ) ;
110110 } ) ;
111111
112+ it ( 'text content' , async ( ) => {
113+ card . appendChild ( document . createTextNode ( 'Text content' ) ) ;
114+ await nextUpdate ( card ) ;
115+ await expect ( card ) . dom . to . equalSnapshot ( ) ;
116+ } ) ;
117+
112118 it ( 'footer' , async ( ) => {
113119 const footer = document . createElement ( 'div' ) ;
114120 footer . setAttribute ( 'slot' , 'footer' ) ;
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ describe('card', () => {
2222 div . style . padding = '20px' ;
2323 } ) ;
2424
25- const cardFixture = ( content ) => fixtureSync ( `<vaadin-card>${ content } </vaadin-card>` , div ) ;
25+ const cardFixture = ( content = '' ) => fixtureSync ( `<vaadin-card>${ content } </vaadin-card>` , div ) ;
2626
2727 const mediaFixture = ( showImage , theme ) => {
2828 const media = showImage
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ describe('card', () => {
4747 div . style . padding = '20px' ;
4848 } ) ;
4949
50- const cardFixture = ( content ) => fixtureSync ( `<vaadin-card>${ content } </vaadin-card>` , div ) ;
50+ const cardFixture = ( content = '' ) => fixtureSync ( `<vaadin-card>${ content } </vaadin-card>` , div ) ;
5151
5252 describe ( 'slot' , ( ) => {
5353 it ( 'content' , async ( ) => {
You can’t perform that action at this time.
0 commit comments