11import React , { useState , useEffect } from "react" ;
2- import { FormVariableIcon , DraggableIcon } from "../SvgIcons/index" ;
2+ import { FormVariableIcon , DraggableIcon } from "../SvgIcons/index" ;
33import { StyleServices } from "@formsflow/service" ;
44
55interface FilterItem {
@@ -26,7 +26,7 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
2626 onUpdate ( filterItems ) ;
2727 } , [ filterItems , onUpdate ] ) ;
2828
29- const onDragStart = ( e : React . DragEvent < HTMLLIElement > , index : number ) => {
29+ const onDragStart = ( e : React . DragEvent < HTMLSpanElement > , index : number ) => {
3030 e . stopPropagation ( ) ;
3131 e . dataTransfer . setData ( "drag-index" , index . toString ( ) ) ;
3232 setDraggingIndex ( index ) ;
@@ -45,7 +45,7 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
4545 const updatedItems = [ ...prevItems ] ;
4646 const [ draggedItem ] = updatedItems . splice ( draggingIndex , 1 ) ;
4747 updatedItems . splice ( targetIndex , 0 , draggedItem ) ;
48- return updatedItems . map ( ( item , index ) => ( { ...item , sortOrder : index + 1 , isMoving : true , } ) ) ;
48+ return updatedItems . map ( ( item , index ) => ( { ...item , sortOrder : index + 1 } ) ) ;
4949 } ) ;
5050 setDraggingIndex ( targetIndex ) ;
5151 } ;
@@ -66,43 +66,52 @@ export const DragandDropSort: React.FC<DragAndDropFilterProps> = ({ items, onUpd
6666 )
6767 ) ;
6868 } ;
69+
70+ const onLabelClick = ( index : number ) => {
71+ onCheckboxChange ( index ) ;
72+ } ;
73+
6974 return (
7075 < div className = "drag-drop-container" >
71- < ul >
76+ < ul >
7277 { filterItems . map ( ( item , index ) => (
73- < li
74- key = { item . name }
75- draggable
76- className = { `draggable-item ${ draggingIndex === index ? "dragging" : "" } ` }
77- onDragOver = { onDragOver }
78- onDrop = { onDrop }
79- onDragEnter = { ( e ) => onDragEnter ( e , index ) }
80- onDragEnd = { onDragEnd }
81- onDragStart = { ( e ) => onDragStart ( e , index ) }
82- >
83- < span
84- className = "draggable-icon"
78+ < li
79+ key = { item . name }
80+ className = { `draggable-item ${ draggingIndex === index ? "dragging" : "" } ` }
81+ onDragOver = { onDragOver }
82+ onDrop = { onDrop }
83+ onDragEnter = { ( e ) => onDragEnter ( e , index ) }
84+ onDragEnd = { onDragEnd }
8585 >
86- < DraggableIcon />
87- </ span >
88- < div className = "checkbox-container" >
89- < input
90- data-testid = { `${ item . name } -checkbox` }
91- type = "checkbox"
92- className = "form-check-input"
93- checked = { item . isChecked }
94- onChange = { ( ) => onCheckboxChange ( index ) }
95- />
96- </ div >
97- { item . label }
98- < div className = "dotted-line" > </ div >
99- { item . isTaskVariable && (
100- < FormVariableIcon color = { darkColor } />
101- ) }
102- </ li >
103- ) ) }
104- </ ul >
86+ < button
87+ className = "draggable-icon drag-as-div"
88+ draggable
89+ onDragStart = { ( e ) => onDragStart ( e , index ) }
90+ >
91+ < DraggableIcon />
92+ </ button >
93+
94+
95+ < div className = "checkbox-container" >
96+ < input
97+ data-testid = { `${ item . name } -checkbox` }
98+ type = "checkbox"
99+ className = "form-check-input"
100+ checked = { item . isChecked }
101+ onChange = { ( ) => onCheckboxChange ( index ) }
102+ />
103+ </ div >
104+
105+ < button className = "label cursor-pointer drag-as-div" onClick = { ( ) => onLabelClick ( index ) } >
106+ { item . label }
107+ </ button >
108+
109+ < div className = "dotted-line" > </ div >
110+
111+ { item . isTaskVariable && < FormVariableIcon color = { darkColor } /> }
112+ </ li >
113+ ) ) }
114+ </ ul >
105115 </ div >
106116 ) ;
107117} ;
108-
0 commit comments