Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
a71b0b0
feat(dnd): allow dragging from the handle only, via new prop: `pointe…
reidbarber Oct 6, 2026
3a136d4
fix RAC examples
reidbarber Oct 7, 2026
dbb99e0
add browser tests
reidbarber Oct 7, 2026
0529751
use grabbing cursor while drag handle is pressed
reidbarber Oct 7, 2026
ad48052
rename 'dragButton' option to 'handle'
reidbarber Oct 7, 2026
e333817
fix: during touch selection mode, allow dragging from the handle itself
reidbarber Oct 7, 2026
eba632a
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Oct 7, 2026
fc5d2ae
fix: identify the nearest draggable ancestor for the handle exemption
reidbarber Oct 7, 2026
013da80
fix browser test to `try await expect.poll(...)` for the cusor
reidbarber Oct 7, 2026
d16d779
skip browser tests for Firefox due to Playwright empty pointerType issue
reidbarber Oct 7, 2026
7aefcbd
fix docs heading level in RAC DnD docs
reidbarber Oct 7, 2026
f4f89ad
include interactive content in S2 docs examples to enforce use-case
reidbarber Oct 7, 2026
e7f041e
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Oct 12, 2026
a3c8b37
update S2 behavior: for pointerDragSource: 'handle', only show drag h…
reidbarber Oct 12, 2026
3dac27d
fix browser test in FF?
reidbarber Oct 12, 2026
5053785
also show handle when items are selected (in new mode, in S2).
reidbarber Oct 12, 2026
5065435
update docs examples to allow reordering
reidbarber Oct 12, 2026
aa427ab
fix media query
reidbarber Oct 13, 2026
c6ccd1e
use css variable for drag handle opacity and cursor to prevent parent…
reidbarber Oct 19, 2026
22f5117
fix: avoid crash when a text node inside a shadow root is dragged
reidbarber Oct 19, 2026
fec905b
fix: reset long press state on pointerdown instead of narrowing drag …
reidbarber Oct 19, 2026
be54783
fix: add drag handle cursor styles to Tailwind starter
reidbarber Oct 19, 2026
3fda37f
fix: apply Button native drag props only via context
reidbarber Oct 19, 2026
a40a5b6
fix(dnd): position custom drag previews relative to the item when dra…
reidbarber Oct 19, 2026
2167059
fix(s2): keep useDragAndDrop hooks stable across renders
reidbarber Oct 19, 2026
ba99e79
fix(dnd): select items on press start when dragging is restricted to …
reidbarber Oct 19, 2026
2e6350c
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Oct 19, 2026
5e788c0
skip shadow test in react 16
reidbarber Oct 19, 2026
09dd3c6
skip browser tests in Firefox
reidbarber Oct 19, 2026
76b7970
add {retry: 2} to browser tests
reidbarber Oct 19, 2026
7c16fd4
fix(s2): keep drag handle mode on touch devices with an expanded hit …
reidbarber Oct 19, 2026
06604dc
fix: don't set a grabbing cursor while dragging
reidbarber Oct 19, 2026
e5d2fc2
address review comments
reidbarber Oct 23, 2026
bef5a78
clean up checkbox hit area width calculation
reidbarber Oct 23, 2026
e8da3ec
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Oct 23, 2026
8433f09
fix lint
reidbarber Oct 23, 2026
08f116c
skip remaining dnd tests in Firefox
reidbarber Nov 2, 2026
f9d3a5a
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Nov 2, 2026
7891b63
chore: merge latest main into drag-from-handle
reidbarber Nov 12, 2026
552f0df
test(dnd): verify non-handle drags are ignored and re-enable S2 Firef…
reidbarber Nov 13, 2026
0cf4f6e
test(dnd): add Shadow DOM button drag handle tests
reidbarber Nov 13, 2026
58d8c7b
feat(Button): support native drag props on ButtonProps
reidbarber Nov 13, 2026
e7cf700
fix(starters): expand touch hit areas for collection drag handles
reidbarber Nov 13, 2026
a4e7318
fix(s2): fix invalid calc() in TreeView drag handle hit area width
reidbarber Nov 13, 2026
fd0957f
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/@react-spectrum/s2/src/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,20 @@ const listitem = style<
type: 'borderTopStartRadius',
value: 'default'
},
'--dragHandleOpacity': {
type: 'opacity',
value: {
default: 0,
isHovered: 1,
isSelected: 1,
touch: 1
}
},
'--dragHandleHitAreaWidth': {
type: 'width',
// Spans the start padding, drag handle, and gap before the checkbox
value: 22
},
forcedColorAdjust: 'none'
});

Expand Down
15 changes: 14 additions & 1 deletion packages/@react-spectrum/s2/src/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,11 @@ const dragCellStyle = style({
alignContent: 'center',
height: 'calc(100% - 1px)',
borderBottomWidth: 0,
backgroundColor: '--rowBackgroundColor'
backgroundColor: '--rowBackgroundColor',
'--dragHandleHitAreaWidth': {
type: 'width',
value: 'full'
}
});

const cellContent = style({
Expand Down Expand Up @@ -1981,6 +1985,15 @@ const row = style<
type: 'color',
value: rowTextColor
},
'--dragHandleOpacity': {
type: 'opacity',
value: {
default: 0,
isHovered: 1,
isSelected: 1,
touch: 1
}
},
// TODO: outline here is to emulate v3 forcedColors experience but runs into the same problem where the sticky column covers the outline
// This doesn't quite work because it gets cut off by the checkbox cell background masking element, figure out another way. Could shrink the checkbox cell's content even more
// and offset it by margin top but that messes up the checkbox centering a bit
Expand Down
56 changes: 38 additions & 18 deletions packages/@react-spectrum/s2/src/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import {ActionButtonGroupContext} from './ActionButtonGroup';
import {ActionMenuContext} from './ActionMenu';
import {baseColor, color, colorMix, focusRing, style} from '../style' with {type: 'macro'};
import {baseColor, color, colorMix, focusRing, size, style} from '../style' with {type: 'macro'};
import {Button, ButtonContext} from 'react-aria-components/Button';
import {centerBaseline} from './CenterBaseline';
import {Checkbox} from './Checkbox';
Expand Down Expand Up @@ -357,6 +357,15 @@ const treeRow = style<TreeItemRenderProps & {isLink?: boolean; isPreviousSelecte
type: 'borderTopStartRadius',
value: 'sm'
},
'--dragHandleOpacity': {
type: 'opacity',
value: {
default: 0,
isHovered: 1,
isSelected: 1,
touch: 1
}
},
borderRadius: 'sm'
});

Expand Down Expand Up @@ -532,12 +541,21 @@ const treeActionMenu = style({
gridArea: 'actionmenu'
});

const treeDragButtonContainer = style({
const treeDragButtonContainer = style<{isCheckboxVisible: boolean}>({
gridArea: 'drag-handle',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
width: 10
width: 10,
'--dragHandleHitAreaWidth': {
type: 'width',
value: {
// Spans the start padding and drag handle, stopping before the expand button.
default: 14,
// Also spans the checkbox's marginStart, which doesn't scale.
isCheckboxVisible: `calc(${size(14)} + 0.5rem)`
}
}
});

let treeRowFocusRing = style({
Expand Down Expand Up @@ -628,6 +646,10 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
allowsDragging,
isDropTarget
}) => {
let hasCheckbox =
selectionMode !== 'none' &&
selectionBehavior === 'toggle' &&
selectionStyle !== 'highlight';
return (
<div
className={treeCellGrid({
Expand Down Expand Up @@ -659,24 +681,22 @@ export const TreeViewItemContent = (props: TreeViewItemContentProps): ReactNode
/>
)}
{allowsDragging && (
<div className={treeDragButtonContainer}>
<div className={treeDragButtonContainer({isCheckboxVisible: hasCheckbox})}>
{!isDisabled && <DragHandleButton isFocusVisibleWithin={isFocusVisibleWithin} />}
</div>
)}
{selectionMode !== 'none' &&
selectionBehavior === 'toggle' &&
selectionStyle !== 'highlight' && (
// TODO: add transition?
<div
className={treeCheckbox({
isDisabled:
isDisabled ||
!state.selectionManager.canSelectItem(id) ||
state.disabledKeys.has(id)
})}>
<Checkbox slot="selection" />
</div>
)}
{hasCheckbox && (
// TODO: add transition?
<div
className={treeCheckbox({
isDisabled:
isDisabled ||
!state.selectionManager.canSelectItem(id) ||
state.disabledKeys.has(id)
})}>
<Checkbox slot="selection" />
</div>
)}
<div
className={style({
gridArea: 'level-padding',
Expand Down
50 changes: 46 additions & 4 deletions packages/@react-spectrum/s2/src/dnd-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/

import {Button} from 'react-aria-components/Button';
import {css, style} from '../style' with {type: 'macro'};
import {DragAndDropContext, DropIndicator} from 'react-aria-components/useDragAndDrop';
import DragHandle from '../ui-icons/DragHandle';
import {ItemDropTarget} from '@react-types/shared';
import React, {useContext} from 'react';
import {style} from '../style' with {type: 'macro'};
import {useVisuallyHidden} from 'react-aria/VisuallyHidden';

let insertionIndicatorWrapper = style<{isDropTarget?: boolean; isRoot?: boolean}>({
Expand Down Expand Up @@ -85,8 +85,28 @@ export function InsertionIndicator({target}: {target: ItemDropTarget}) {
);
}

let dragButton = style({
let dragButton = style<{
isFocusVisible: boolean;
isPressed: boolean;
isHandlePointerSource: boolean;
isFocusVisibleWithin: boolean;
}>({
color: 'inherit',
// Preserve the handle's size when hover ends during native drag initiation.
opacity: {
default: 1,
isHandlePointerSource: {
default: '--dragHandleOpacity',
isFocusVisibleWithin: 1
}
},
cursor: {
default: 'default',
isHandlePointerSource: {
default: 'grab',
isPressed: 'grabbing'
}
},
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
Expand Down Expand Up @@ -114,13 +134,35 @@ let dragButton = style({
}
});

// Expands the handle's touch target without affecting layout. The pseudo-element is positioned

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should apply this in the starters as well, they're a little small

// relative to the item (or cell), spanning its full height from the start edge to
// --dragHandleHitAreaWidth, so it doesn't overlap the selection checkbox.
const dragHandleHitArea = css(`
@media not ((hover: hover) and (pointer: fine)) {
&::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
inset-inline-start: 0;
width: var(--dragHandleHitAreaWidth);
}
}
`);
Comment on lines +137 to +151

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListView:

Image

TreeView:

Image

TableView:

Image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export function DragHandleButton({isFocusVisibleWithin}: {isFocusVisibleWithin: boolean}) {
let {visuallyHiddenProps} = useVisuallyHidden();
let {dragAndDropHooks} = useContext(DragAndDropContext) ?? {};
let isHandlePointerSource = dragAndDropHooks?.pointerDragSource === 'handle';
let isHidden = !isFocusVisibleWithin && !isHandlePointerSource;
return (
<Button
slot="drag"
style={!isFocusVisibleWithin ? visuallyHiddenProps.style : {}}
className={dragButton}>
style={isHidden ? visuallyHiddenProps.style : {}}
className={renderProps =>
dragButton({...renderProps, isHandlePointerSource, isFocusVisibleWithin}) +
(isHandlePointerSource ? ' ' + dragHandleHitArea : '')
}>
<DragHandle size="M" />
</Button>
);
Expand Down
10 changes: 9 additions & 1 deletion packages/@react-spectrum/s2/src/useDragAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ export type {DragAndDrop};
export interface DragAndDropOptions<T = object> extends Omit<
RACDragAndDropOptions<T>,
'renderDropIndicator'
> {}
> {
/**
* Whether mouse and touch dragging can start from the entire item or only from its drag handle.
* Keyboard and screen reader dragging are unaffected.
*
* @default 'item'
*/
pointerDragSource?: 'item' | 'handle';
}

/**
* Provides the hooks required to enable drag and drop behavior for a drag and drop compatible
Expand Down
24 changes: 19 additions & 5 deletions packages/@react-spectrum/s2/stories/ListView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import FolderOpen from '../spectrum-illustrations/linear/FolderOpen';
import {IllustratedMessage} from '../src/IllustratedMessage';
import {Image} from '../src/Image';
import {Key} from '@react-types/shared';
import {ListView, ListViewItem} from '../src/ListView';
import {ListView, ListViewItem, ListViewProps} from '../src/ListView';
import {MenuItem} from '../src/Menu';
import type {Meta, StoryObj} from '@storybook/react';
import {ReactNode, useState} from 'react';
Expand Down Expand Up @@ -710,7 +710,10 @@ function CustomDragPreview(props) {
);
}

function ReorderExample(props) {
function ReorderExample({
pointerDragSource,
...props
}: Partial<ListViewProps<any>> & {pointerDragSource?: 'item' | 'handle'}) {
let list = useListData({
initialItems: reorderItems
});
Expand All @@ -733,7 +736,8 @@ function ReorderExample(props) {
},
renderDragPreview: items => (
<CustomDragPreview parentList={list} items={items} overflowMode={props.overflowMode} />
)
),
pointerDragSource
});

return (
Expand All @@ -753,9 +757,19 @@ function ReorderExample(props) {
);
}

export const Reorderable: Story = {
export const Reorderable: StoryObj<typeof ReorderExample> = {
render: args => <ReorderExample {...args} />,
name: 'Drag and drop reordering'
name: 'Drag and drop reordering',
argTypes: {
pointerDragSource: {
control: 'radio',
options: ['item', 'handle']
},
selectionMode: {
control: 'radio',
options: ['none', 'single', 'multiple']
}
}
Comment thread
snowystinger marked this conversation as resolved.
Resolved
};

let folderList1 = [
Expand Down
Loading
Loading