11import { html , LitElement , nothing , type TemplateResult } from 'lit' ;
22import { property , state } from 'lit/decorators.js' ;
3+ import { cache } from 'lit/directives/cache.js' ;
34import { ifDefined } from 'lit/directives/if-defined.js' ;
45import { addThemingController } from '../../theming/theming-controller.js' ;
56import { registerComponent } from '../common/definitions/register.js' ;
@@ -25,6 +26,7 @@ interface ValidationContainerConfig {
2526
2627const VALIDATION_SLOTS_SELECTOR = 'slot:not([name="helper-text"])' ;
2728const ALL_SLOTS_SELECTOR = 'slot' ;
29+ const QUERY_CONFIG : AssignedNodesOptions = { flatten : true } ;
2830
2931function getValidationSlots (
3032 element : IgcValidationContainerComponent
@@ -38,7 +40,7 @@ function hasProjection(element: IgcValidationContainerComponent): boolean {
3840 const allSlots =
3941 element . renderRoot . querySelectorAll < HTMLSlotElement > ( ALL_SLOTS_SELECTOR ) ;
4042 return Array . from ( allSlots ) . every ( ( slot ) =>
41- isEmpty ( slot . assignedElements ( { flatten : true } ) )
43+ isEmpty ( slot . assignedElements ( QUERY_CONFIG ) )
4244 ) ;
4345}
4446
@@ -47,15 +49,14 @@ function hasProjectedValidation(
4749 slotName ?: string
4850) : boolean {
4951 const slots = Array . from ( getValidationSlots ( element ) ) ;
50- const config : AssignedNodesOptions = { flatten : true } ;
5152
5253 if ( slotName ) {
5354 return slots
5455 . filter ( ( slot ) => slot . name === slotName )
55- . some ( ( slot ) => ! isEmpty ( slot . assignedElements ( config ) ) ) ;
56+ . some ( ( slot ) => ! isEmpty ( slot . assignedElements ( QUERY_CONFIG ) ) ) ;
5657 }
5758
58- return slots . some ( ( slot ) => ! isEmpty ( slot . assignedElements ( config ) ) ) ;
59+ return slots . some ( ( slot ) => ! isEmpty ( slot . assignedElements ( QUERY_CONFIG ) ) ) ;
5960}
6061
6162/* blazorSuppress */
@@ -208,9 +209,9 @@ export default class IgcValidationContainerComponent extends LitElement {
208209 }
209210
210211 protected override render ( ) : TemplateResult {
211- const slots = this . invalid
212- ? this . _renderValidationSlots ( this . target . validity )
213- : nothing ;
212+ const slots = cache (
213+ this . invalid ? this . _renderValidationSlots ( this . target . validity ) : nothing
214+ ) ;
214215
215216 return html `
216217 < div part =${ partMap ( { 'helper-text' : true , empty : hasProjection ( this ) } ) } >
0 commit comments