@@ -22,7 +22,9 @@ import { TextArea } from '../form-items/text-area';
2222import { TextInput } from '../form-items/text-input' ;
2323import { Icon , MynahIcons } from '../icon' ;
2424import { Overlay , OverlayHorizontalDirection , OverlayVerticalDirection } from '../overlay' ;
25+ import { MoreContentIndicator } from '../more-content-indicator' ;
2526const TOOLTIP_DELAY = 350 ;
27+ const FORM_DESCRIPTION_COLLAPSED_HEIGHT_RATIO = 16 ; // Show less content when collapsed
2628export interface ChatItemFormItemsWrapperProps {
2729 tabId : string ;
2830 chatItem : Partial < ChatItem > ;
@@ -75,16 +77,53 @@ export class ChatItemFormItemsWrapper {
7577 chatItemOption . value = chatItemOption . options ?. [ 0 ] ?. value ;
7678 }
7779 }
78- let description ;
80+ let description : ExtendedHTMLElement | undefined ;
7981 if ( chatItemOption . description != null ) {
80- description = DomBuilder . getInstance ( ) . build ( {
82+ const descriptionContent = DomBuilder . getInstance ( ) . build ( {
8183 type : 'span' ,
84+ classNames : [ 'mynah-ui-form-item-description-content' ] ,
85+ children : [ chatItemOption . description ]
86+ } ) ;
87+
88+ description = DomBuilder . getInstance ( ) . build ( {
89+ type : 'div' ,
8290 testId : testIds . chatItem . chatItemForm . description ,
8391 classNames : [ 'mynah-ui-form-item-description' ] ,
84- children : [
85- chatItemOption . description ,
86- ]
92+ children : [ descriptionContent ]
8793 } ) ;
94+
95+ // Add MoreContentIndicator for long descriptions
96+ const moreContentIndicator = new MoreContentIndicator ( {
97+ icon : MynahIcons . DOWN_OPEN ,
98+ border : false ,
99+ onClick : ( ) => {
100+ if ( description ?. hasClass ( 'mynah-ui-form-item-description-collapsed' ) === true ) {
101+ description . removeClass ( 'mynah-ui-form-item-description-collapsed' ) ;
102+ moreContentIndicator . update ( { icon : MynahIcons . UP_OPEN } ) ;
103+ } else {
104+ description ?. addClass ( 'mynah-ui-form-item-description-collapsed' ) ;
105+ moreContentIndicator . update ( { icon : MynahIcons . DOWN_OPEN } ) ;
106+ }
107+ } ,
108+ testId : `${ testIds . chatItem . chatItemForm . description } -more-content-indicator`
109+ } ) ;
110+
111+ description . insertChild ( 'beforeend' , moreContentIndicator . render ) ;
112+
113+ // Check if content needs collapsing after a short delay
114+ setTimeout ( ( ) => {
115+ const collapsedHeight = window . innerHeight / FORM_DESCRIPTION_COLLAPSED_HEIGHT_RATIO ;
116+
117+ // Show MoreContentIndicator if content exceeds the collapsed max-height
118+ if ( descriptionContent . scrollHeight > collapsedHeight ) {
119+ description ?. addClass ( 'mynah-ui-form-item-description-auto-collapse' ) ;
120+ description ?. addClass ( 'mynah-ui-form-item-description-collapsed' ) ;
121+ // Set the collapsed height dynamically
122+ description ?. style . setProperty ( '--form-description-collapsed-height' , `${ collapsedHeight } px` ) ;
123+ } else {
124+ moreContentIndicator . render . addClass ( 'hidden' ) ;
125+ }
126+ } , 50 ) ;
88127 }
89128 const fireModifierAndEnterKeyPress = ( ) : void => {
90129 if ( ( chatItemOption as TextBasedFormItem ) . checkModifierEnterKeyPress === true && this . isFormValid ( ) ) {
0 commit comments