Repository navigation
feat(dnd): support dragging collection items from handles only #10738
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
reidbarber
wants to merge
45
commits into
main
Choose a base branch
from
drag-from-handle
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.
+2,117
−72
Open
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 3a136d4
fix RAC examples
reidbarber dbb99e0
add browser tests
reidbarber 0529751
use grabbing cursor while drag handle is pressed
reidbarber ad48052
rename 'dragButton' option to 'handle'
reidbarber e333817
fix: during touch selection mode, allow dragging from the handle itself
reidbarber eba632a
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber fc5d2ae
fix: identify the nearest draggable ancestor for the handle exemption
reidbarber 013da80
fix browser test to `try await expect.poll(...)` for the cusor
reidbarber d16d779
skip browser tests for Firefox due to Playwright empty pointerType issue
reidbarber 7aefcbd
fix docs heading level in RAC DnD docs
reidbarber f4f89ad
include interactive content in S2 docs examples to enforce use-case
reidbarber e7f041e
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber a3c8b37
update S2 behavior: for pointerDragSource: 'handle', only show drag h…
reidbarber 3dac27d
fix browser test in FF?
reidbarber 5053785
also show handle when items are selected (in new mode, in S2).
reidbarber 5065435
update docs examples to allow reordering
reidbarber aa427ab
fix media query
reidbarber c6ccd1e
use css variable for drag handle opacity and cursor to prevent parent…
reidbarber 22f5117
fix: avoid crash when a text node inside a shadow root is dragged
reidbarber fec905b
fix: reset long press state on pointerdown instead of narrowing drag …
reidbarber be54783
fix: add drag handle cursor styles to Tailwind starter
reidbarber 3fda37f
fix: apply Button native drag props only via context
reidbarber a40a5b6
fix(dnd): position custom drag previews relative to the item when dra…
reidbarber 2167059
fix(s2): keep useDragAndDrop hooks stable across renders
reidbarber ba99e79
fix(dnd): select items on press start when dragging is restricted to …
reidbarber 2e6350c
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber 5e788c0
skip shadow test in react 16
reidbarber 09dd3c6
skip browser tests in Firefox
reidbarber 76b7970
add {retry: 2} to browser tests
reidbarber 7c16fd4
fix(s2): keep drag handle mode on touch devices with an expanded hit …
reidbarber 06604dc
fix: don't set a grabbing cursor while dragging
reidbarber e5d2fc2
address review comments
reidbarber bef5a78
clean up checkbox hit area width calculation
reidbarber e8da3ec
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber 8433f09
fix lint
reidbarber 08f116c
skip remaining dnd tests in Firefox
reidbarber f9d3a5a
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber 7891b63
chore: merge latest main into drag-from-handle
reidbarber 552f0df
test(dnd): verify non-handle drags are ignored and re-enable S2 Firef…
reidbarber 0cf4f6e
test(dnd): add Shadow DOM button drag handle tests
reidbarber 58d8c7b
feat(Button): support native drag props on ButtonProps
reidbarber e7cf700
fix(starters): expand touch hit areas for collection drag handles
reidbarber a4e7318
fix(s2): fix invalid calc() in TreeView drag handle hit area width
reidbarber fd0957f
Merge remote-tracking branch 'origin/main' into drag-from-handle
reidbarber 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}>({ | ||
|
|
@@ -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', | ||
|
|
@@ -114,13 +134,35 @@ let dragButton = style({ | |
| } | ||
| }); | ||
|
|
||
| // Expands the handle's touch target without affecting layout. The pseudo-element is positioned | ||
| // 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
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.
Member
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. |
||
|
|
||
| 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> | ||
| ); | ||
|
|
||
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
Oops, something went wrong.
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.
probably should apply this in the starters as well, they're a little small