-
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
Resize column via keyboard #3357
base: main
Are you sure you want to change the base?
Changes from 4 commits
8448fdd
a2c31e7
2734915
8065535
67b7819
1d19772
8b6403c
7fa97cb
1e7c8be
e14b606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,7 @@ function DataGrid<R, SR, K extends Key>( | |
|
||
function handleKeyDown(event: KeyboardEvent<HTMLDivElement>) { | ||
const { idx, rowIdx, mode } = selectedPosition; | ||
const column = columns[idx]; | ||
if (mode === 'EDIT') return; | ||
|
||
if (onCellKeyDown && isRowIdxWithinViewportBounds(rowIdx)) { | ||
|
@@ -534,7 +535,7 @@ function DataGrid<R, SR, K extends Key>( | |
{ | ||
mode: 'SELECT', | ||
row, | ||
column: columns[idx], | ||
column, | ||
rowIdx, | ||
selectCell | ||
}, | ||
|
@@ -568,6 +569,19 @@ function DataGrid<R, SR, K extends Key>( | |
} | ||
} | ||
|
||
if (column.resizable && isCtrlKeyHeldDown(event) && event.shiftKey) { | ||
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. need some insights here @amanmahajan7 @nstepien
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. I decided to go with using the 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. I think we can always allow keyboard resizing if the column can be resized. I don't think we need an api to disable it unless there is a use case. We allow keyboard navigation on the header cell and can allow resizing when the cell is focused.
Questions:
|
||
const leftKey = isRtl ? 39 : 37; | ||
const rightKey = isRtl ? 37 : 39; | ||
if (keyCode === leftKey || keyCode === rightKey) { | ||
const width = getColumnWidth(column); | ||
const step = 10; | ||
const isIncrease = keyCode === rightKey; | ||
const newWidth = isIncrease ? Number(width) + step : Number(width) - step; | ||
handleColumnResizeLatest(column, newWidth); | ||
return; | ||
} | ||
} | ||
|
||
switch (event.key) { | ||
case 'Escape': | ||
setCopiedCell(null); | ||
|
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.
why do we need to check
isRowIdxWithinViewportBounds
before callonCellKeyDown
?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.
I think because row would be undefined otherwise. Same for summary row. We may have to add a type
HEADER | ROW | SUMMARY