-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Move row focus logic to <TreeGrid />, add renderSummaryRow
#3976
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
Open
amanmahajan7
wants to merge
7
commits into
main
Choose a base branch
from
am-treegrid
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−120
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
442e4be
Move row selection logic to TreeGrid, add `renderSummaryRow`
amanmahajan7 d384712
Merge branch 'main' into am-treegrid
amanmahajan7 4ca38de
Rename
amanmahajan7 3b23533
Header row is not focusable
amanmahajan7 94ae711
Merge branch 'main' into am-treegrid
amanmahajan7 d45a317
Merge branch 'main' into am-treegrid
nstepien 8e373bd
Merge branch 'main' into am-treegrid
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 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
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { useCallback, useMemo } from 'react'; | |||||
| import type { Key } from 'react'; | ||||||
|
|
||||||
| import { useLatestFunc } from './hooks'; | ||||||
| import { assertIsValidKeyGetter, getLeftRightKey } from './utils'; | ||||||
| import { assertIsValidKeyGetter, classnames, getLeftRightKey } from './utils'; | ||||||
| import type { | ||||||
| CellClipboardEvent, | ||||||
| CellCopyArgs, | ||||||
|
|
@@ -14,6 +14,7 @@ import type { | |||||
| Maybe, | ||||||
| Omit, | ||||||
| RenderRowProps, | ||||||
| RenderSummaryRowProps, | ||||||
| RowHeightArgs, | ||||||
| RowsChangeData | ||||||
| } from './types'; | ||||||
|
|
@@ -24,6 +25,8 @@ import type { DataGridProps } from './DataGrid'; | |||||
| import { useDefaultRenderers } from './DataGridDefaultRenderersContext'; | ||||||
| import GroupedRow from './GroupRow'; | ||||||
| import { defaultRenderRow } from './Row'; | ||||||
| import { rowFocusable, rowSelectedClassname } from './style/row'; | ||||||
| import SummaryRowComponent from './SummaryRow'; | ||||||
|
Collaborator
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.
Suggested change
|
||||||
|
|
||||||
| export interface TreeDataGridProps<R, SR = unknown, K extends Key = Key> extends Omit< | ||||||
| DataGridProps<R, SR, K>, | ||||||
|
|
@@ -380,17 +383,23 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({ | |||||
| lastFrozenColumnIndex, | ||||||
| draggedOverCellIdx, | ||||||
| selectedCellEditor, | ||||||
| isTreeGrid, | ||||||
| className, | ||||||
| ...rowProps | ||||||
| }: RenderRowProps<R, SR> | ||||||
| ) { | ||||||
| const isPositionOnRow = rowProps.selectedCellIdx === -1; | ||||||
| const tabIndex = isPositionOnRow ? 0 : -1; | ||||||
| className = classnames(className, rowFocusable, isPositionOnRow && rowSelectedClassname); | ||||||
|
|
||||||
| if (isGroupRow(row)) { | ||||||
| const { startRowIndex } = row; | ||||||
| return ( | ||||||
| <GroupedRow | ||||||
| key={key} | ||||||
| {...rowProps} | ||||||
| aria-rowindex={headerAndTopSummaryRowsCount + startRowIndex + 1} | ||||||
| className={className} | ||||||
| tabIndex={tabIndex} | ||||||
| row={row} | ||||||
| groupBy={groupBy} | ||||||
| toggleGroup={toggleGroupLatest} | ||||||
|
|
@@ -411,15 +420,16 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({ | |||||
| 'aria-rowindex': ariaRowIndex, | ||||||
| row, | ||||||
| rowClass, | ||||||
| className, | ||||||
| tabIndex, | ||||||
| onCellMouseDown, | ||||||
| onCellClick, | ||||||
| onCellDoubleClick, | ||||||
| onCellContextMenu, | ||||||
| onRowChange, | ||||||
| lastFrozenColumnIndex, | ||||||
| draggedOverCellIdx, | ||||||
| selectedCellEditor, | ||||||
| isTreeGrid | ||||||
| selectedCellEditor | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -442,7 +452,8 @@ export function TreeDataGrid<R, SR = unknown, K extends Key = Key>({ | |||||
| onCellPaste={rawOnCellPaste ? handleCellPaste : undefined} | ||||||
| renderers={{ | ||||||
| ...renderers, | ||||||
| renderRow | ||||||
| renderRow, | ||||||
| renderSummaryRow | ||||||
| }} | ||||||
| /> | ||||||
| ); | ||||||
|
|
@@ -452,6 +463,25 @@ function defaultGroupIdGetter(groupKey: string, parentId: string | undefined) { | |||||
| return parentId !== undefined ? `${parentId}__${groupKey}` : groupKey; | ||||||
| } | ||||||
|
|
||||||
| function renderSummaryRow<R, SR>( | ||||||
| key: React.Key, | ||||||
| { selectedCellIdx, className, ...props }: RenderSummaryRowProps<R, SR> | ||||||
| ) { | ||||||
| const isPositionOnRow = selectedCellIdx === -1; | ||||||
| const tabIndex = isPositionOnRow ? 0 : -1; | ||||||
| className = classnames(className, rowFocusable, isPositionOnRow && rowSelectedClassname); | ||||||
|
|
||||||
| return ( | ||||||
| <SummaryRowComponent | ||||||
| key={key} | ||||||
| tabIndex={tabIndex} | ||||||
| selectedCellIdx={selectedCellIdx} | ||||||
| className={className} | ||||||
| {...props} | ||||||
| /> | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| function isReadonlyArray(arr: unknown): arr is readonly unknown[] { | ||||||
| return Array.isArray(arr); | ||||||
| } | ||||||
Oops, something went wrong.
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.
I removed it for now as we do not focus on the header row