Skip to content

Commit f258ead

Browse files
authored
Fix DnD stories so the droppable listbox actually works (#3580)
1 parent 1d21d12 commit f258ead

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

packages/@react-aria/dnd/stories/DroppableListBox.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export function DroppableListBoxExample(props) {
9090

9191
export const DroppableListBox = React.forwardRef(function (props: any, ref) {
9292
let domRef = React.useRef<HTMLDivElement>(null);
93-
let onDrop = action('onDrop');
93+
let onDrop = async (e) => {
94+
action('onDrop')(e);
95+
props.onDrop?.(e);
96+
};
9497
let state = useListState({...props, selectionMode: 'multiple'});
9598
let keyboardDelegate = new ListKeyboardDelegate(state.collection, new Set(), domRef);
9699

@@ -104,7 +107,7 @@ export const DroppableListBox = React.forwardRef(function (props: any, ref) {
104107
let dropState = useDroppableCollectionState({
105108
collection: state.collection,
106109
selectionManager: state.selectionManager,
107-
getDropOperation(target, allowedOperations) {
110+
getDropOperation: (target, _, allowedOperations) => {
108111
if (target.type === 'root') {
109112
return 'move';
110113
}
@@ -114,17 +117,15 @@ export const DroppableListBox = React.forwardRef(function (props: any, ref) {
114117
}
115118

116119
return target.dropPosition !== 'on' ? allowedOperations[0] : 'copy';
117-
}
120+
},
121+
onDrop
118122
});
119123

120124
let {collectionProps} = useDroppableCollection({
121125
keyboardDelegate,
122126
dropTargetDelegate: new ListDropTargetDelegate(state.collection, domRef),
123127
onDropActivate: chain(action('onDropActivate'), console.log),
124-
onDrop: async e => {
125-
onDrop(e);
126-
props.onDrop?.(e);
127-
}
128+
onDrop
128129
}, dropState, domRef);
129130

130131
let {listBoxProps} = useListBox({

packages/@react-aria/dnd/stories/VirtualizedListBox.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ const acceptedTypes = ['item', 'folder'];
9898

9999
export const VirtualizedListBox = React.forwardRef(function (props: any, ref) {
100100
let domRef = React.useRef<HTMLDivElement>(null);
101-
let onDrop = action('onDrop');
101+
let onDrop = async (e) => {
102+
action('onDrop')(e);
103+
props.onDrop?.(e);
104+
};
102105
let state = useListState({...props, selectionMode: 'multiple'});
103106

104107
React.useImperativeHandle(ref, () => ({
@@ -131,7 +134,8 @@ export const VirtualizedListBox = React.forwardRef(function (props: any, ref) {
131134
}
132135

133136
return target.dropPosition !== 'on' ? allowedOperations[0] : 'copy';
134-
}
137+
},
138+
onDrop
135139
});
136140

137141
let collator = useCollator({usage: 'search', sensitivity: 'base'});
@@ -151,10 +155,7 @@ export const VirtualizedListBox = React.forwardRef(function (props: any, ref) {
151155
keyboardDelegate: layout,
152156
dropTargetDelegate: layout,
153157
onDropActivate: chain(action('onDropActivate'), console.log),
154-
onDrop: async e => {
155-
onDrop(e);
156-
props.onDrop?.(e);
157-
}
158+
onDrop
158159
}, dropState, domRef);
159160

160161
let {listBoxProps} = useListBox({

0 commit comments

Comments
 (0)