在文档中它说:
DragHandleProps
需要应用到您想成为拖动手柄的节点。这是需要应用于<Draggable />
节点的一些道具。最简单的方法是将道具散布到可拖动节点({...provided.dragHandleProps}
)上。但是,如果您还需要响应它们,也欢迎您对这些道具进行修补。DragHandleProps
将null
何时isDragDisabled
设置为true。
dragHandleProps
类型信息
type DragHandleProps = {|
// what draggable the handle belongs to
'data-rbd-drag-handle-draggable-id': DraggableId,
// What DragDropContext the drag handle is in
'data-rbd-drag-handle-context-id': ContextId,
// Id of hidden element that contains the lift instruction (nicer screen reader text)
'aria-labelledby': ElementId,
// Allow tabbing to this element
tabIndex: number,
// Stop html5 drag and drop
draggable: boolean,
onDragStart: (event: DragEvent) => void,
|};
我想附加onDragStart
到 ,Draggable
以便仅在拖动特定的一组元素时触发它(而不是将其附加到DragDropContext
)。使用我做的文档中的示例:
<Draggable draggableId="draggable-1" index={0}>
{(provided, snapshot) => (
<div
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
onDragStart={() => console.log('onDragStart')}
>
Drag me!
</div>
)}
</Draggable>
但是它似乎不起作用。任何想法如何使它工作?