-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: add drag-to-select for multiple webframes #2853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d20e7c6
feat: add drag-to-select for multiple webframes
drfarrell 67dbb86
style: make drag selection border thinner
drfarrell 3c0f9bf
style: use Onlook's custom blue-500 color for drag selection
drfarrell 0497fed
fix: address performance and logic issues in drag selection
drfarrell 1320b58
feat: improve drag selection visual feedback and prevent element hover
drfarrell fba3f3c
style: enhance drag selection visual feedback with proper teal colors
drfarrell a41bcab
fix: change iframe outer border to teal during drag selection
drfarrell da04fd0
Update colors
drfarrell 990fffa
fix: add global mouseup listener for reliable drag termination
drfarrell 041dac4
merge main
Kitenite 027714d
handle click
Kitenite 4087cb6
fix types
Kitenite 6aa6cc3
add drag deadzone
Kitenite f9bf313
update drag
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/web/client/src/app/project/[id]/_components/canvas/overlay/drag-select.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| 'use client'; | ||
|
|
||
| import { colors } from '@onlook/ui/tokens'; | ||
| import { observer } from 'mobx-react-lite'; | ||
|
|
||
| interface DragSelectOverlayProps { | ||
| startX: number; | ||
| startY: number; | ||
| endX: number; | ||
| endY: number; | ||
| isSelecting: boolean; | ||
| } | ||
|
|
||
| export const DragSelectOverlay = observer(({ startX, startY, endX, endY, isSelecting }: DragSelectOverlayProps) => { | ||
| if (!isSelecting) { | ||
| return null; | ||
| } | ||
|
|
||
| const left = Math.min(startX, endX); | ||
| const top = Math.min(startY, endY); | ||
| const width = Math.abs(endX - startX); | ||
| const height = Math.abs(endY - startY); | ||
|
|
||
| return ( | ||
| <div | ||
| className="absolute pointer-events-none" | ||
| style={{ | ||
| left: `${left}px`, | ||
| top: `${top}px`, | ||
| width: `${width}px`, | ||
| height: `${height}px`, | ||
| border: `1px solid ${colors.blue[500]}`, | ||
| backgroundColor: `${colors.blue[500]}1A`, // 10% opacity (1A in hex) | ||
| }} | ||
| /> | ||
| ); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current
onMouseLeavehandler only terminates drag selection when no mouse button is pressed (e.buttons === 0), but doesn't handle the case where the user drags outside the canvas and then releases the mouse button elsewhere. This could leave the application in a perpetual drag selecting state.Consider adding a global mouse up event listener when drag selecting starts:
This would ensure the drag selection state is properly reset regardless of where the mouse button is released.
Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.