Overview
The drag-and-drop interface allows you to:- Drag fields from the palette to add them to your layout
- Reorder fields within the canvas by dragging
- Combine fields into rows (up to 3 per row)
- Create new rows by dropping fields above or below existing ones
- Move fields between steps in multi-step forms
Interface Components
The drag-and-drop system has three main areas:1. The Palette (Left Sidebar)
Location: “Campos detectados” section in the sidebar What it shows: Form fields that are NOT currently in the canvas- Underline on hover: Field is draggable
- Green “Requerido” badge: Field is required
- Grab cursor (
cursor: grab): Ready to drag - Grabbing cursor (
cursor: grabbing): Currently dragging
Sidebar.tsx:32-48 and index.css for palette styling.
2. The Canvas (Center)
Location: Main editing area showing your form layout What it shows: All fields currently in your layout, organized by steps and rows- Drag handle (
⋮⋮): Click and hold to drag a field - Drop indicators: Blue lines show where field will be placed
- Semi-transparent: Field being dragged
- Highlighted zones: Valid drop targets
3. The Drag Overlay
Location: Floats under your cursor while dragging What it shows: A preview of the field you’re dragging Implemented inApp.tsx:252-261.
Drop Zones Explained
When dragging a field over an existing field in the canvas, you can drop in three positions:Top Zone (20% of field height)
Action: Creates a NEW ROW above the target fieldCenter Zone (60% of field height)
Action: Combines with target field in the SAME ROW (max 3 fields per row)- Drop on left half of target → inserts to the left
- Drop on right half of target → inserts to the right
Bottom Zone (20% of field height)
Action: Creates a NEW ROW below the target fieldStep Drop Zone
Action: Drops field at the end of a step (creates new row)useLayoutDnd.ts:132-136, 240-252.
Dragging from Palette to Canvas
Adding fields from the palette is the primary way to build your layout.Locate Available Fields
Scroll to the “Campos detectados” section in the left sidebar.You’ll see all fields that aren’t currently in your canvas.
Start Dragging
Click and hold on any field in the palette.The cursor changes to a grabbing hand, and a preview appears under your cursor.
Position Over Target
Drag over the canvas to your desired location.Drop zones will appear as you hover over existing fields or empty step areas.
Drop Options from Palette
Option A: Create New Row
Option A: Create New Row
Drop on the top or bottom zone of any existing field.The field is placed in a new row at the specified position (useLayoutStore.ts:287-323).
Option B: Add to Existing Row
Option B: Add to Existing Row
Drop in the center zone of an existing field.The field is added to the same row, up to a maximum of 3 fields (useLayoutStore.ts:324-364).
Option C: Drop on Step Zone
Option C: Drop on Step Zone
Drop anywhere in the empty space of a step.The field is added in a new row at the end of that step (useLayoutDnd.ts:249-251).
Reordering Fields Within Canvas
Once fields are in the canvas, you can reorganize them.Moving Within Same Step
Drag to New Position
Move your cursor over another field in the same step.Drop zones appear: top, center, or bottom.
- Same row combination:
moveFieldWithinStep()combines fields if dropped in center zone - New row creation:
moveFieldToNewRow()creates a new row if dropped on top/bottom zones
useLayoutDnd.ts:272-308, 475-550.
Moving Between Steps
In multi-step forms, you can move fields across steps:
Implementation:
moveFieldBetweenSteps() in useLayoutStore.ts:164-204.
Creating Multi-Column Rows
Rows can contain up to 3 fields for compact layouts.Adding a Second Field to a Row
Drag Another Field Over It
Drag a field from the palette or another row.Position your cursor over the center zone of the target field.
Choose Left or Right
- Left half: New field inserts to the left
- Right half: New field inserts to the right
Adding a Third Field to a Row
Repeat the same process to add a third field. Result: Three fields in one row, responsive and evenly spaced.Maximum Fields Per Row
You cannot add more than 3 fields to a row:Removing Fields
Remove fields to simplify your form or experiment with different layouts.Click the Delete Button
Click the × button on the field.Note: Required fields don’t have a delete button.
Field Returns to Palette
The field disappears from the canvas.It automatically appears in the “Campos detectados” palette.
removeFieldFromStep() in useLayoutStore.ts:238-265.
When a field is removed, its row is also deleted if it becomes empty (useLayoutStore.ts:246-251).
Step Management
Steps themselves can be reordered (though this is less common).Reordering Steps
The step header acts as a drag handle:- Click and hold the step header (not the title input)
- Drag the entire step up or down
- Drop when you see the desired position
reorderSteps() in useLayoutStore.ts:149-163.
Deleting Steps
See the Building Forms Guide for details.Visual Feedback and Indicators
Cursor States
| State | Cursor | Meaning |
|---|---|---|
| Hovering over palette field | grab | Field is draggable |
| Dragging field | grabbing | Currently dragging |
| Over valid drop zone | default | Can drop here |
| Over invalid target | not-allowed | Cannot drop |
Drop Position Classes
The canvas applies CSS classes to show drop positions:LayoutBuilder.tsx:157 and index.css for styling.
Drag Overlay
While dragging, a semi-transparent preview follows your cursor showing:- Field label
- Required badge (if applicable)
Keyboard and Mouse Interactions
Mouse Actions
| Action | Result |
|---|---|
Click drag handle (⋮⋮) + hold | Start dragging field |
| Drag over field (top 20%) | Show “drop above” indicator |
| Drag over field (center 60%) | Show “combine” indicator |
| Drag over field (bottom 20%) | Show “drop below” indicator |
| Release mouse button | Complete the drop |
Click × on field | Remove field (non-required only) |
Activation Constraint
A drag must move 8 pixels before activating:Touch Support
The drag-and-drop system supports touch devices:- Long press to start dragging
- Drag with finger
- Release to drop
Advanced Techniques
Quick Field Removal and Re-addition
Scenario: You want to temporarily remove a field to try different layouts.- Click
×to remove the field - It appears in the palette
- Experiment with other fields
- Drag the removed field back from the palette when ready
Building Row-First Layouts
Technique: Create all your rows first, then fill them.- Drag one field from palette to create row 1
- Drag another field, drop below to create row 2
- Repeat for all rows
- Go back and combine fields into rows as needed
Reorganizing Entire Steps
Scenario: You want to swap step order. Option 1 - Reorder Steps:- Drag step header to new position
- All fields move with the step
- Drag each field from step 1 to step 2 drop zone
- Repeat until all fields are moved
- Delete empty step
Troubleshooting
Field won't drop
Field won't drop
Possible causes:
- Target row already has 3 fields (max limit)
- Field is already in the canvas (no duplicates allowed)
- Trying to drop on field in different step (must use step drop zone)
Drag doesn't start
Drag doesn't start
Possible causes:
- Not clicking the drag handle (
⋮⋮) on canvas fields - Not holding click long enough (8px activation distance)
- JavaScript error in console
Field appears in canvas AND palette
Field appears in canvas AND palette
Cause: State synchronization bug in
collectFieldNames().Solution: Refresh the page. This shouldn’t happen but if it does, report the issue.Drop zones not appearing
Drop zones not appearing
Possible causes:
- CSS not loaded properly
- DragOver handler not firing
index.css is loaded and useLayoutDnd.ts:105-208 is working.Performance Considerations
Large Forms
For forms with 20+ fields:- Palette rendering is efficient (no virtualization needed)
- Canvas updates are optimized via Zustand
- Drag operations are smooth due to @dnd-kit’s performance
Reducing Layout Shifts
- Drop indicators use
::beforeand::afterpseudo-elements to avoid layout reflow - Drag overlay uses fixed positioning
- Field dimensions are preserved during drag
Tips for Efficient Form Building
Next Steps
Building Forms
Learn the complete form building workflow
Exporting Modules
Export your layout as a HubSpot module
