@@ -135,12 +135,7 @@ export class PidCollapsible {
135135 this . updateAppearance ( ) ;
136136
137137 // When open, ensure content dimensions are properly calculated
138- if ( this . open ) {
139- // Use setTimeout to ensure DOM is updated before recalculating
140- setTimeout ( ( ) => {
141- this . recalculateContentDimensions ( ) ;
142- } , 0 ) ;
143- }
138+ if ( this . open ) this . recalculateContentDimensions ( ) ;
144139 }
145140
146141 /**
@@ -152,20 +147,9 @@ export class PidCollapsible {
152147 }
153148
154149 componentWillLoad ( ) {
155- // Initialize dimensions but delay actual calculation until content is rendered
156- if ( this . initialWidth ) {
157- this . currentWidth = this . initialWidth ;
158- } else {
159- // Default to 75% width if no initial width is provided
160- this . currentWidth = '75%' ;
161- }
162-
163- if ( this . initialHeight ) {
164- this . currentHeight = this . initialHeight ;
165- } else {
166- // Use default height initially, will be recalculated after content renders
167- this . currentHeight = CONSTANTS . DEFAULT_HEIGHT ;
168- }
150+ // Default to 75% width if no initial width is provided
151+ this . currentWidth = this . initialWidth || '75%' ; // Changed from DEFAULT_WIDTH to use 75% (w-3/4)
152+ this . currentHeight = this . initialHeight || CONSTANTS . DEFAULT_HEIGHT ;
169153
170154 // Initialize dark mode
171155 this . initializeDarkMode ( ) ;
@@ -177,17 +161,17 @@ export class PidCollapsible {
177161 this . addBrowserCompatibilityListeners ( ) ;
178162 this . addComponentEventListeners ( ) ;
179163
180- // When component is initially open, ensure dimensions are properly calculated after rendering
181- if ( this . open ) {
182- // // Make sure expanded state is set correctly for open components
183- // this.open = true;
184-
185- // Use a small delay to ensure the DOM is fully rendered
186- setTimeout ( ( ) => {
187- // Force recalculation of dimensions for open components
188- this . recalculateContentDimensions ( ) ;
189- } , 100 ) ;
190- }
164+ // // When component is initially open, ensure dimensions are properly calculated after rendering
165+ // if (this.open) {
166+ // // // Make sure expanded state is set correctly for open components
167+ // // this.open = true;
168+ //
169+ // // Use a small delay to ensure the DOM is fully rendered
170+ // setTimeout(() => {
171+ // // Force recalculation of dimensions for open components
172+ // this.recalculateContentDimensions();
173+ // }, 100);
174+ // }
191175
192176 // Add clearfix for Safari - prevent text flow issues
193177 if ( / ^ ( (? ! c h r o m e | a n d r o i d ) .) * s a f a r i / i. test ( navigator . userAgent ) ) {
@@ -346,7 +330,6 @@ export class PidCollapsible {
346330 if ( ! this . currentHeight || this . currentHeight === `${ this . lineHeight } px` ) {
347331 this . currentHeight = this . initialHeight || `${ optimalHeight } px` ;
348332 } else {
349- // Set the height to exactly match the content height plus padding
350333 this . currentHeight = `${ optimalHeight } px` ;
351334 }
352335
@@ -601,14 +584,12 @@ export class PidCollapsible {
601584 */
602585 private calculateContentDimensions ( ) {
603586 const contentElement = this . el . querySelector ( '.flex-grow' ) ;
604- // Get the actual visible content width/height (not just scroll dimensions)
605- const contentWidth = contentElement ? Math . max ( ( contentElement as HTMLElement ) . offsetWidth , contentElement ?. scrollWidth || 0 ) : CONSTANTS . MIN_WIDTH ;
606- const contentHeight = contentElement ? Math . max ( ( contentElement as HTMLElement ) . offsetHeight , contentElement ?. scrollHeight || 0 ) : CONSTANTS . MIN_HEIGHT ;
587+ const contentWidth = contentElement ?. scrollWidth || CONSTANTS . MIN_WIDTH ;
588+ const contentHeight = contentElement ?. scrollHeight || CONSTANTS . MIN_HEIGHT ;
607589
608590 // Add padding for better appearance, plus footer height if footer is shown
609591 const footerHeight = this . showFooter ? CONSTANTS . FOOTER_HEIGHT : 0 ;
610592 const maxWidth = contentWidth + CONSTANTS . PADDING_WIDTH ;
611- // Use actual content height rather than adding arbitrary padding
612593 const maxHeight = contentHeight + CONSTANTS . PADDING_HEIGHT + footerHeight ;
613594
614595 return { contentWidth, contentHeight, maxWidth, maxHeight } ;
@@ -624,34 +605,15 @@ export class PidCollapsible {
624605
625606 const { contentWidth, contentHeight, maxWidth, maxHeight } = dimensions ;
626607
627- // Calculate initial width based on content but prefer initialWidth if provided
628- let optimalWidth ;
629- if ( this . initialWidth ) {
630- // Use initialWidth directly if provided
631- this . currentWidth = this . initialWidth ;
632- } else {
633- // Calculate a content-based width with minimal padding
634- optimalWidth = Math . min ( Math . max ( contentWidth + CONSTANTS . PADDING_WIDTH , CONSTANTS . MIN_WIDTH ) , maxWidth ) ;
635- // Default to 75% if we don't have specific content dimensions
636- this . currentWidth = contentWidth > 0 ? `${ optimalWidth } px` : '75%' ;
637- }
608+ // Always set exact content dimensions to prevent resizing beyond content
609+ // Ensure width is within minimum and maximum bounds
610+ const optimalWidth = Math . min ( Math . max ( contentWidth + CONSTANTS . PADDING_WIDTH , CONSTANTS . MIN_WIDTH ) , maxWidth ) ;
611+ this . currentWidth = `${ optimalWidth } px` ;
638612
639- // Calculate optimal height based on actual content
613+ // Calculate optimal height including padding and footer if needed
640614 const footerHeight = this . showFooter ? CONSTANTS . FOOTER_HEIGHT : 0 ;
641-
642- // Use more precise content height calculation to prevent extra space
643- // Add minimal padding to prevent content being cut off
644- const minPadding = 20 ; // Minimal padding to prevent content being cut off
645- const calculatedHeight = contentHeight + minPadding + footerHeight ;
646-
647- // Use initialHeight if provided, otherwise use calculated height
648- if ( this . initialHeight ) {
649- this . currentHeight = this . initialHeight ;
650- } else {
651- // Ensure height is between min height and max height constraints
652- const optimalHeight = Math . min ( Math . max ( calculatedHeight , CONSTANTS . MIN_HEIGHT ) , maxHeight ) ;
653- this . currentHeight = `${ optimalHeight } px` ;
654- }
615+ const optimalHeight = Math . min ( Math . max ( contentHeight + CONSTANTS . PADDING_HEIGHT + footerHeight , CONSTANTS . MIN_HEIGHT ) , maxHeight ) ;
616+ this . currentHeight = `${ optimalHeight } px` ;
655617
656618 // Store these dimensions for future reference
657619 this . lastExpandedWidth = this . currentWidth ;
@@ -663,14 +625,6 @@ export class PidCollapsible {
663625 this . el . style . width = this . currentWidth ;
664626 this . el . style . height = this . currentHeight ;
665627
666- // Set min-height/min-width to prevent resizing smaller than content
667- this . el . style . minHeight = `${ Math . max ( calculatedHeight , CONSTANTS . MIN_HEIGHT ) } px` ;
668- this . el . style . minWidth = `${ CONSTANTS . MIN_WIDTH } px` ;
669-
670- // Also set max-height/max-width to prevent excessive resizing
671- this . el . style . maxHeight = `${ maxHeight } px` ;
672- this . el . style . maxWidth = `${ maxWidth } px` ;
673-
674628 // Remove the optimization class after updates are applied
675629 this . el . classList . remove ( 'resizing' ) ;
676630 } ) ;
@@ -807,9 +761,7 @@ export class PidCollapsible {
807761
808762 // Ensure consistent state and reset flag
809763 setTimeout ( ( ) => {
810- if ( details . open !== this . open ) {
811- details . open = this . open ;
812- }
764+ details . open = this . open ;
813765 setTimeout ( ( ) => {
814766 this . isToggling = false ;
815767 } , 100 ) ;
0 commit comments