-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Refactor listview to always focus the row #3000
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 all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
3580959
initial work to focus the row instead of the cell
LFDanLu e51bd3f
cleanup
LFDanLu 928549a
tentative approach to always skip focusing the cell
LFDanLu 2216e98
retaining focus on Listview focusable child when it is clicked
LFDanLu dac22a8
making ListView specific keyboard delegate
LFDanLu b540f23
fixing pageUp/Down operations when within the ListView row
LFDanLu 2ebabe1
adding tests
LFDanLu 2a92a70
fixing tests after rebase
LFDanLu 312aaed
refactor to have outer div behave as both gridcell and grid row
LFDanLu dd9dac5
fixing Home/End
LFDanLu 17a11bd
fixing test and getting rid of erroneous data id
LFDanLu d9eb366
cleanup
LFDanLu 303304c
lint
LFDanLu 0fe13e6
removing todo
LFDanLu b4a4f40
updating lint so we check that a dep is actually needed before throwing
LFDanLu 11302a3
removing private
LFDanLu c9ba923
pulling triggerPress outside the act
LFDanLu db7fbe7
Merge branch 'main' into refactor_listview_row_focus_2
LFDanLu 471139a
Merge branch 'main' into refactor_listview_row_focus_2
LFDanLu f2ef4ef
tentative approach to use ListLayout instead of making a ListGrid key…
LFDanLu 0476f4f
fixing build
LFDanLu 2ea0c5a
removing useGridRow to ensure the focused key will always be a row
LFDanLu b30d604
Merge branch 'main' of github.com:adobe/react-spectrum into refactor_…
LFDanLu 53e8c7a
cleanup
LFDanLu e659966
Merge branch 'main' of github.com:adobe/react-spectrum into refactor_…
LFDanLu 3f7f3d8
adding listview story decorator for before and after focusable elements
LFDanLu 7cf09be
Merge branch 'main' of github.com:adobe/react-spectrum into refactor_…
LFDanLu 6c02faf
making the story input fields only appear at certain screen widths
LFDanLu 9eda1f9
Merge branch 'main' into refactor_listview_row_focus_2
LFDanLu e4086bf
addressing review comments
LFDanLu 5ed6df6
Merge branch 'main' into refactor_listview_row_focus_2
LFDanLu 71809a1
Merge branch 'main' into refactor_listview_row_focus_2
LFDanLu 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -381,4 +381,3 @@ export class GridKeyboardDelegate<T, C extends GridCollection<T>> implements Key | |
| return null; | ||
| } | ||
| } | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ import {ListViewContext} from './ListView'; | |
| import {mergeProps} from '@react-aria/utils'; | ||
| import React, {useContext, useRef} from 'react'; | ||
| import {useButton} from '@react-aria/button'; | ||
| import {useGridCell, useGridRow, useGridSelectionCheckbox} from '@react-aria/grid'; | ||
| import {useGridCell, useGridSelectionCheckbox} from '@react-aria/grid'; | ||
| import {useHover, usePress} from '@react-aria/interactions'; | ||
| import {useLocale} from '@react-aria/i18n'; | ||
| import {useVisuallyHidden} from '@react-aria/visually-hidden'; | ||
|
|
@@ -32,47 +32,42 @@ export function ListViewItem(props) { | |
| let { | ||
| item, | ||
| isEmphasized, | ||
| dragHooks | ||
| dragHooks, | ||
| hasActions | ||
| } = props; | ||
| let cellNode = [...item.childNodes][0]; | ||
| let {state, dragState, onAction, isListDraggable, layout} = useContext(ListViewContext); | ||
|
|
||
| let {state, dragState, isListDraggable, layout} = useContext(ListViewContext); | ||
| let {direction} = useLocale(); | ||
| let rowRef = useRef<HTMLDivElement>(); | ||
| let cellRef = useRef<HTMLDivElement>(); | ||
| let { | ||
| isFocusVisible: isFocusVisibleWithin, | ||
| focusProps: focusWithinProps | ||
| } = useFocusRing({within: true}); | ||
| let {isFocusVisible, focusProps} = useFocusRing(); | ||
| let allowsInteraction = state.selectionManager.selectionMode !== 'none' || onAction; | ||
| let allowsInteraction = state.selectionManager.selectionMode !== 'none' || hasActions; | ||
| let isDisabled = !allowsInteraction || state.disabledKeys.has(item.key); | ||
| let isDraggable = dragState?.isDraggable(item.key) && !isDisabled; | ||
| let {hoverProps, isHovered} = useHover({isDisabled}); | ||
| let {pressProps, isPressed} = usePress({isDisabled}); | ||
| let {rowProps} = useGridRow({ | ||
|
|
||
| // We only make use of useGridCell here to allow for keyboard navigation to the focusable children of the row. | ||
| // The actual grid cell of the ListView is inert since we don't want to ever focus it to decrease screenreader | ||
| // verbosity, so we pretend the row node is the cell for interaction purposes. useGridRow is never used since | ||
| // it would conflict with useGridCell if applied to the same node. | ||
| let {gridCellProps} = useGridCell({ | ||
| node: item, | ||
| focusMode: 'cell', | ||
| isVirtualized: true, | ||
| onAction: onAction ? () => onAction(item.key) : undefined, | ||
| shouldSelectOnPressUp: isListDraggable | ||
| }, state, rowRef); | ||
| let {gridCellProps} = useGridCell({ | ||
| node: cellNode, | ||
| focusMode: 'cell' | ||
| }, state, cellRef); | ||
| delete gridCellProps['aria-colindex']; | ||
|
|
||
| let draggableItem: DraggableItemResult; | ||
| if (isListDraggable) { | ||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| draggableItem = dragHooks.useDraggableItem({key: item.key}, dragState); | ||
| } | ||
| const mergedProps = mergeProps( | ||
| gridCellProps, | ||
| hoverProps, | ||
| focusWithinProps, | ||
| focusProps | ||
| ); | ||
| let {checkboxProps} = useGridSelectionCheckbox({...props, key: item.key}, state); | ||
|
|
||
| let {checkboxProps} = useGridSelectionCheckbox({...props, key: item.key}, state); | ||
| let dragButtonRef = React.useRef(); | ||
| let {buttonProps} = useButton({ | ||
| ...draggableItem?.dragButtonProps, | ||
|
|
@@ -98,6 +93,23 @@ export function ListViewItem(props) { | |
| let isSelected = state.selectionManager.isSelected(item.key); | ||
| let showDragHandle = isDraggable && isFocusVisibleWithin; | ||
| let {visuallyHiddenProps} = useVisuallyHidden(); | ||
| let rowProps = { | ||
| role: 'row', | ||
| 'aria-label': item.textValue, | ||
| 'aria-selected': state.selectionManager.selectionMode !== 'none' ? isSelected : undefined, | ||
| 'aria-rowindex': item.index + 1 | ||
| }; | ||
|
|
||
| const mergedProps = mergeProps( | ||
| gridCellProps, | ||
| rowProps, | ||
| pressProps, | ||
| isDraggable && draggableItem?.dragProps, | ||
| hoverProps, | ||
| focusWithinProps, | ||
| focusProps | ||
| ); | ||
|
|
||
| let isFirstRow = item.prevKey == null; | ||
| let isLastRow = item.nextKey == null; | ||
| // Figure out if the ListView content is equal or greater in height to the container. If so, we'll need to round the bottom | ||
|
|
@@ -112,7 +124,7 @@ export function ListViewItem(props) { | |
|
|
||
| return ( | ||
| <div | ||
| {...mergeProps(rowProps, pressProps, isDraggable && draggableItem?.dragProps)} | ||
| {...mergedProps} | ||
| className={ | ||
| classNames( | ||
| listStyles, | ||
|
|
@@ -124,6 +136,7 @@ export function ListViewItem(props) { | |
| } | ||
| ref={rowRef}> | ||
| <div | ||
| // TODO: refactor the css here now that we are focusing the row? | ||
|
Member
Author
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. Will be looking at refactoring the css after a couple of other ListView PRs w/ heavy css updates are merged |
||
| className={ | ||
| classNames( | ||
| listStyles, | ||
|
|
@@ -143,8 +156,8 @@ export function ListViewItem(props) { | |
| } | ||
| ) | ||
| } | ||
| ref={cellRef} | ||
| {...mergedProps}> | ||
| role="gridcell" | ||
| aria-colindex={1}> | ||
| <Grid UNSAFE_className={listStyles['react-spectrum-ListViewItem-grid']}> | ||
| {isListDraggable && | ||
| <div className={listStyles['react-spectrum-ListViewItem-draghandle-container']}> | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.