-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Move drag handle outside the cell #3334
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b47cbab
Move drag handle outside the cell
amanmahajan7 0ffe17d
alternate approach
amanmahajan7 393f83b
revert
amanmahajan7 b9fed4e
Remove margin
amanmahajan7 0c6aa9e
Fix drag handle position on frozen column
amanmahajan7 f790914
Merge branch 'main' into am-drag-handle
amanmahajan7 9629075
Fix typo
amanmahajan7 e90b57c
Fix colSpan
amanmahajan7 9863de0
Simplify styles
amanmahajan7 7eef6ab
Update src/DragHandle.tsx
amanmahajan7 2f51f79
Update src/DataGrid.tsx
amanmahajan7 e06ccf5
Fix if condition
amanmahajan7 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 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 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 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 |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { css } from '@linaria/core'; | ||
import clsx from 'clsx'; | ||
|
||
import type { CalculatedColumn, FillEvent, Position } from './types'; | ||
import type { DataGridProps, SelectCellState } from './DataGrid'; | ||
|
||
const cellDragHandle = css` | ||
@layer rdg.DragHandle { | ||
--rdg-drag-handle-width: 8px; | ||
z-index: 0; | ||
cursor: move; | ||
position: absolute; | ||
inset-inline-end: 0; | ||
inset-block-end: 0; | ||
inline-size: 8px; | ||
block-size: 8px; | ||
background-color: var(--rdg-selection-color); | ||
align-self: end; | ||
justify-self: end; | ||
amanmahajan7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
&:hover { | ||
inline-size: 16px; | ||
|
@@ -22,9 +24,21 @@ const cellDragHandle = css` | |
} | ||
`; | ||
|
||
const cellDragHandleFrozenClassname = css` | ||
@layer rdg.DragHandle { | ||
z-index: 1; | ||
position: sticky; | ||
|
||
&:hover { | ||
--rdg-drag-handle-width: 16px; | ||
} | ||
} | ||
`; | ||
|
||
const cellDragHandleClassname = `rdg-cell-drag-handle ${cellDragHandle}`; | ||
|
||
interface Props<R, SR> extends Pick<DataGridProps<R, SR>, 'rows' | 'onRowsChange'> { | ||
gridRowStart: number; | ||
columns: readonly CalculatedColumn<R, SR>[]; | ||
selectedPosition: SelectCellState; | ||
latestDraggedOverRowIdx: React.MutableRefObject<number | undefined>; | ||
|
@@ -35,6 +49,7 @@ interface Props<R, SR> extends Pick<DataGridProps<R, SR>, 'rows' | 'onRowsChange | |
} | ||
|
||
export default function DragHandle<R, SR>({ | ||
gridRowStart, | ||
rows, | ||
columns, | ||
selectedPosition, | ||
|
@@ -45,6 +60,9 @@ export default function DragHandle<R, SR>({ | |
setDragging, | ||
setDraggedOverRowIdx | ||
}: Props<R, SR>) { | ||
const { idx, rowIdx } = selectedPosition; | ||
const column = columns[idx]; | ||
|
||
function handleMouseDown(event: React.MouseEvent<HTMLDivElement>) { | ||
if (event.buttons !== 1) return; | ||
setDragging(true); | ||
|
@@ -70,7 +88,6 @@ export default function DragHandle<R, SR>({ | |
const overRowIdx = latestDraggedOverRowIdx.current; | ||
if (overRowIdx === undefined) return; | ||
|
||
const { rowIdx } = selectedPosition; | ||
const startRowIndex = rowIdx < overRowIdx ? rowIdx + 1 : overRowIdx; | ||
const endRowIndex = rowIdx < overRowIdx ? overRowIdx + 1 : rowIdx; | ||
updateRows(startRowIndex, endRowIndex); | ||
|
@@ -79,11 +96,10 @@ export default function DragHandle<R, SR>({ | |
|
||
function handleDoubleClick(event: React.MouseEvent<HTMLDivElement>) { | ||
event.stopPropagation(); | ||
updateRows(selectedPosition.rowIdx + 1, rows.length); | ||
updateRows(rowIdx + 1, rows.length); | ||
} | ||
|
||
function updateRows(startRowIdx: number, endRowIdx: number) { | ||
const { idx, rowIdx } = selectedPosition; | ||
const column = columns[idx]; | ||
const sourceRow = rows[rowIdx]; | ||
const updatedRows = [...rows]; | ||
|
@@ -105,7 +121,15 @@ export default function DragHandle<R, SR>({ | |
|
||
return ( | ||
<div | ||
className={cellDragHandleClassname} | ||
style={{ | ||
gridColumnStart: column.idx + 1, | ||
amanmahajan7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
gridRowStart, | ||
insetInlineStart: | ||
column.frozen && typeof column.width === 'number' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this can cause any issues |
||
? `calc(var(--rdg-frozen-left-${column.idx}) + ${column.width}px - var(--rdg-drag-handle-width))` | ||
: undefined | ||
}} | ||
className={clsx(cellDragHandleClassname, column.frozen && cellDragHandleFrozenClassname)} | ||
onMouseDown={handleMouseDown} | ||
onDoubleClick={handleDoubleClick} | ||
/> | ||
|
This file contains 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 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 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
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.
Do we need to check whether the selected cell is not in a summary row?
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.
isCellWithinViewportBounds
would return false for header and summary rows. There is another functionisCellWithinSelectionBounds
that can be used to check header and summary rows as well