Skip to content

Commit 28dfecc

Browse files
LFDanLureidbarber
andauthored
Hide dragging ListView row from Talkback during virtual drag (#3492)
if a listview was only draggable, the dragged row element and drag handle was focusable via TalkBack. Hide the row element so that users dont need to perform an extra swipe to focus the drag handle Co-authored-by: Reid Barber <[email protected]>
1 parent 5f16c3f commit 28dfecc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import {DraggableCollectionOptions, DraggableCollectionState, useDraggableCollectionState} from '@react-stately/dnd';
22
import {DraggableCollectionProps} from '@react-types/shared';
3-
import {DraggableItemProps, DraggableItemResult, DragPreview, useDraggableItem} from '@react-aria/dnd';
3+
import {DraggableItemProps, DraggableItemResult, DragPreview, isVirtualDragging, useDraggableItem} from '@react-aria/dnd';
44
import {useMemo} from 'react';
55

66
export interface DragHooks {
77
useDraggableCollectionState(props: Omit<DraggableCollectionOptions, 'getItems'>): DraggableCollectionState,
88
useDraggableItem(props: DraggableItemProps, state: DraggableCollectionState): DraggableItemResult,
9-
DragPreview: typeof DragPreview
9+
DragPreview: typeof DragPreview,
10+
isVirtualDragging(): boolean
1011
}
1112

1213
export interface DragHookOptions extends Omit<DraggableCollectionProps, 'preview'> {}
@@ -17,6 +18,7 @@ export function useDragHooks(options: DragHookOptions): DragHooks {
1718
return useDraggableCollectionState({...props, ...options});
1819
},
1920
useDraggableItem,
20-
DragPreview
21+
DragPreview,
22+
isVirtualDragging
2123
}), [options]);
2224
}

packages/@react-spectrum/list/src/ListViewItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export function ListViewItem<T>(props: ListViewItemProps<T>) {
129129
let {visuallyHiddenProps} = useVisuallyHidden();
130130

131131
let dropProps = isDroppable ? droppableItem?.dropProps : {'aria-hidden': droppableItem?.dropProps['aria-hidden']};
132+
let isVirtualDragging = dropHooks?.isVirtualDragging() || dragHooks?.isVirtualDragging();
132133
const mergedProps = mergeProps(
133134
rowProps,
134135
draggableItem?.dragProps,
@@ -138,7 +139,7 @@ export function ListViewItem<T>(props: ListViewItemProps<T>) {
138139
focusProps,
139140
// Remove tab index from list row if performing a screenreader drag. This prevents TalkBack from focusing the row,
140141
// allowing for single swipe navigation between row drop indicator
141-
dropHooks?.isVirtualDragging() && {tabIndex: null}
142+
isVirtualDragging && {tabIndex: null}
142143
);
143144

144145
let isFirstRow = item.prevKey == null;

0 commit comments

Comments
 (0)