Skip to content

Commit 5058508

Browse files
committed
fix(DragDropSort): support custom drag button aria-label and fix falsy id overlay
Adds a `dragButtonAriaLabel` prop to `Draggable` that forwards to `DragButton`, allowing consumers to provide a translated accessible name for the drag handle via `DraggableObject.props`. Also fixes `DragDropContainer` rendering the literal text "0" as the drag overlay when a draggable item has a falsy numeric id (e.g. `0`). The `activeId && getDragOverlay()` expression short-circuits to `0` which React renders as text. Changed to `activeId != null`.
1 parent 6b93dbd commit 5058508

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
240240
};
241241

242242
const getDragOverlay = () => {
243-
if (!activeId) {
243+
if (activeId == null) {
244244
return;
245245
}
246246
const item = findItem(activeId, findContainer(activeId));
@@ -290,7 +290,7 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
290290
);
291291
};
292292

293-
const dragOverlay = <DragOverlay>{activeId && getDragOverlay()}</DragOverlay>;
293+
const dragOverlay = <DragOverlay>{activeId != null && getDragOverlay()}</DragOverlay>;
294294

295295
const portalTarget = typeof appendTo === 'function' ? appendTo() : appendTo || document.body;
296296

packages/react-drag-drop/src/components/DragDrop/Draggable.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@ export interface DraggableProps extends React.HTMLProps<HTMLDivElement> {
1313
id?: string;
1414
/** Flag indicating the draggable element should include a drag button. */
1515
useDragButton?: boolean;
16+
/** Accessible name of the drag button. */
17+
dragButtonAriaLabel?: string;
1618
}
1719

1820
export const Draggable: React.FunctionComponent<DraggableProps> = ({
1921
children,
2022
id,
2123
className,
2224
useDragButton = false,
25+
dragButtonAriaLabel,
2326
...props
2427
}: DraggableProps) => {
2528
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
@@ -38,7 +41,7 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
3841
style={style}
3942
{...props}
4043
>
41-
<DragButton {...attributes} {...listeners} />
44+
<DragButton {...attributes} {...listeners} {...(dragButtonAriaLabel && { 'aria-label': dragButtonAriaLabel })} />
4245
{children}
4346
</div>
4447
) : (

0 commit comments

Comments
 (0)