@@ -106,7 +106,7 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
106106 } ,
107107 { } as Record < string , FormVariable >
108108 ) ;
109-
109+
110110 isInternalUpdateRef . current = false ; // Mark as external update
111111 setAlternativeLabels ( sanitized ) ;
112112 } else if ( ! savedFormVariables ) {
@@ -139,22 +139,22 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
139139 delete updated [ variableKey ] ;
140140 return updated ;
141141 } ) ;
142-
142+
143143 } else {
144144 // Remove variable from alternativeLabels when switch is turned off
145145 // Only save to temp storage if user actually typed a value (different from default and labelOfComponent)
146146 setAlternativeLabels ( ( prev ) => {
147147 const existing = prev [ variableKey ] ;
148148 const defaultAltVariable = systemVariable ?. altVariable || "" ;
149149 const labelOfComponent = systemVariable ?. labelOfComponent || "" ;
150-
150+
151151 // Only save if there's a value AND it's different from both the default and labelOfComponent
152152 // (meaning user actually typed something custom)
153- const hasCustomValue = existing ?. altVariable &&
154- existing . altVariable !== defaultAltVariable &&
153+ const hasCustomValue = existing ?. altVariable &&
154+ existing . altVariable !== defaultAltVariable &&
155155 existing . altVariable !== labelOfComponent &&
156156 existing . altVariable . trim ( ) !== "" ;
157-
157+
158158 if ( hasCustomValue ) {
159159 tempInputValuesRef . current [ variableKey ] = existing . altVariable ;
160160 setTempInputValues ( ( tempPrev ) => ( {
@@ -175,7 +175,39 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
175175 return updated ;
176176 } ) ;
177177 }
178- } , [ ] ) ;
178+ } , [ ] ) ;
179+ // Handle back button click
180+ const handleBack = useCallback ( ( ) => {
181+ const highlightedElement = document . querySelector ( ".formio-hilighted" ) ;
182+ if ( highlightedElement ) {
183+ highlightedElement . classList . remove ( "formio-hilighted" ) ;
184+ }
185+ setShowElement ( false ) ;
186+ } , [ ] ) ;
187+
188+ // Handle pill click
189+ const handlePillClick = useCallback ( ( variable ) => {
190+ setSelectedComponent ( {
191+ key : variable . key ,
192+ type : variable . type ,
193+ label : variable . labelOfComponent ,
194+ altVariable : variable . altVariable ,
195+ isFormVariable : variable . isFormVariable ?? true ,
196+ } ) ;
197+ setShowElement ( true ) ;
198+
199+ const existing = document . querySelector ( ".formio-hilighted" ) ;
200+ if ( existing ) {
201+ existing . classList . remove ( "formio-hilighted" ) ;
202+ }
203+
204+ const component = document . querySelector ( `.formio-component-${ variable . key } ` ) ;
205+ if ( component ) {
206+ component . classList . add ( "formio-hilighted" ) ;
207+ component . scrollIntoView ( { behavior : 'smooth' , block : 'center' } ) ;
208+ }
209+ } , [ ] ) ;
210+
179211 // Form Variable Handlers
180212 const handleAddAlternative = useCallback ( ( ) => {
181213 if ( selectedComponent . key ) {
@@ -217,8 +249,9 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
217249 altVariable : alternativeLabels [ variable . key ] ?. altVariable || variable . altVariable || "" ,
218250 } ) ) ;
219251 const columns = [
220- { field : 'type' , headerName : 'Type' , flex : 2.8 , sortable : false , width : 140 } ,
221- { field : 'variable' , headerName : 'Variable' , flex : 1.5 , sortable : false , width : 250 ,
252+ { field : 'type' , headerName : 'Type' , flex : 2.8 , sortable : false , width : 140 } ,
253+ {
254+ field : 'variable' , headerName : 'Variable' , flex : 1.5 , sortable : false , width : 250 ,
222255 renderCell : ( params ) => (
223256 < span style = { { color : StyleServices . getCSSVariable ( '--ff-gray-darkest' ) } } > { params . value } </ span >
224257 )
@@ -234,7 +267,7 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
234267 const variableKey = params . row . variable ;
235268 const isChecked = ! ! alternativeLabels [ variableKey ] ;
236269 const systemVariable = SystemVariables . find ( v => v . key === variableKey ) ;
237-
270+
238271 return (
239272 < Switch
240273 type = "primary"
@@ -279,13 +312,13 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
279312 isLoading
280313 ? < div className = "form-spinner" > </ div >
281314 : < FormComponent
282- form = { form }
283- setShowElement = { setShowElement }
284- detailsRef = { detailsRef }
285- alternativeLabels = { alternativeLabels }
286- setSelectedComponent = { setSelectedComponent }
287- ignoreKeywords = { ignoreKeywords }
288- />
315+ form = { form }
316+ setShowElement = { setShowElement }
317+ detailsRef = { detailsRef }
318+ alternativeLabels = { alternativeLabels }
319+ setSelectedComponent = { setSelectedComponent }
320+ ignoreKeywords = { ignoreKeywords }
321+ />
289322 }
290323 </ div >
291324 ) ;
@@ -302,7 +335,7 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
302335 < div className = "slideout-variable-selected show" >
303336 < div className = "head" >
304337 < div className = "RHS-header" >
305- < span className = "back-button" onClick = { ( ) => setShowElement ( false ) } >
338+ < span className = "back-button" onClick = { handleBack } >
306339 < BackIcon color = { BackIconColor } /> { t ( "Back" ) }
307340 </ span >
308341 </ div >
@@ -320,21 +353,21 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
320353 < span className = "value" > { selectedComponent . key } </ span >
321354 </ div >
322355 < div className = "alternative-label-container" >
323- < span className = "label" >
324- { t ( "Add alternative label" ) }
325- </ span >
326- < CustomTextInput
327- ariaLabel = "Add alternative label input"
328- dataTestId = "Add-alternative-input"
329- value = { selectedComponent . altVariable }
330- setValue = { ( value ) =>
331- setSelectedComponent ( ( prev ) => ( {
332- ...prev ,
333- altVariable : value ,
334- } ) )
335- }
336- disabled = { disabled }
337- />
356+ < span className = "label" >
357+ { t ( "Add alternative label" ) }
358+ </ span >
359+ < CustomTextInput
360+ ariaLabel = "Add alternative label input"
361+ dataTestId = "Add-alternative-input"
362+ value = { selectedComponent . altVariable }
363+ setValue = { ( value ) =>
364+ setSelectedComponent ( ( prev ) => ( {
365+ ...prev ,
366+ altVariable : value ,
367+ } ) )
368+ }
369+ disabled = { disabled }
370+ />
338371 </ div >
339372 < V8CustomButton
340373 dataTestId = "Add-alternative-btn"
@@ -359,40 +392,43 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
359392 { /* Pills or empty state - only shown when panel is hidden */ }
360393 { ! showElement && (
361394 < div className = "h-100" >
362- < div className = "RHS-header" >
363- < span className = "form-variables-title" > Form Variables</ span >
364- </ div >
395+ < div className = "RHS-header" >
396+ < span className = "form-variables-title" > Form Variables</ span >
397+ </ div >
365398 { filteredVariablePills . length > 0 ? (
366399 < div className = "pill-container" >
367400 { filteredVariablePills . map (
368- ( { key, altVariable, labelOfComponent } : any ) => (
369- < div
370- key = { key }
371- className = "variable-card"
372- >
373- { disabled ? null : < div
374- className = "variable-card-close"
375- onClick = { ( e ) => {
376- e . stopPropagation ( ) ;
377- removeSelectedVariable ( key ) ;
378- } }
401+ ( variable : any ) => {
402+ const { key, altVariable, labelOfComponent } = variable ;
403+ return (
404+ < div
405+ key = { key }
406+ className = "variable-card"
407+ onClick = { ( ) => handlePillClick ( variable ) }
379408 >
380- < CloseIcon
381- color = { BackIconColor }
382- dataTestId = { `pill-remove-icon-${ key } ` }
383- />
384- </ div > }
385- < div className = "d-flex flex-column" >
386- < span className = "variable-title" >
387- { altVariable || labelOfComponent }
388- </ span >
389- < span className = "variable-subtitle" >
390- { key }
391- </ span >
409+ { disabled ? null : < div
410+ className = "variable-card-close"
411+ onClick = { ( e ) => {
412+ e . stopPropagation ( ) ;
413+ removeSelectedVariable ( key ) ;
414+ } }
415+ >
416+ < CloseIcon
417+ color = { BackIconColor }
418+ dataTestId = { `pill-remove-icon-${ key } ` }
419+ />
420+ </ div > }
421+ < div className = "d-flex flex-column" >
422+ < span className = "variable-title" >
423+ { altVariable || labelOfComponent }
424+ </ span >
425+ < span className = "variable-subtitle" >
426+ { key }
427+ </ span >
428+ </ div >
392429 </ div >
393- </ div >
394- )
395- ) }
430+ ) ;
431+ } ) }
396432 </ div >
397433 ) : (
398434 < div className = "d-flex flex-column h-100 pt-4 align-items-center" >
@@ -422,7 +458,7 @@ export const VariableSelection: React.FC<VariableSelectionProps> = React.memo(
422458 { tabKey === "form" &&
423459 < div className = "variable-page-body-form" >
424460 < div className = "variable-left-container" >
425- { renderFormContent ( ) }
461+ { renderFormContent ( ) }
426462 </ div >
427463 < div
428464 className = "variable-right-container"
0 commit comments