Skip to content

fix(DragDropSort): support custom drag button aria-label and fix falsy id overlay#12417

Open
logonoff wants to merge 1 commit intopatternfly:mainfrom
logonoff:12416-dnd
Open

fix(DragDropSort): support custom drag button aria-label and fix falsy id overlay#12417
logonoff wants to merge 1 commit intopatternfly:mainfrom
logonoff:12416-dnd

Conversation

@logonoff
Copy link
Copy Markdown
Member

@logonoff logonoff commented May 7, 2026

What: Closes #12416

  • 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.
  • 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.

Additional issues: N/A

Summary by CodeRabbit

  • Bug Fixes

    • Fixed drag-overlay and drop-target detection to correctly handle all valid identifiers (including falsy-but-valid values like 0), preventing unintended overlay suppression and ensuring consistent collision/visual feedback during dragging.
  • New Features

    • Added optional aria-label support for drag buttons so drag handles can include an accessible name when enabled, improving assistive technology support.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6d8b9ad2-df4f-45d2-984b-4b48d2983ee9

📥 Commits

Reviewing files that changed from the base of the PR and between a42b543 and 1a2dc95.

📒 Files selected for processing (2)
  • packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
  • packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx

Walkthrough

Adds an optional dragButtonAriaLabel prop to Draggable and replaces truthy activeId checks with explicit nullish checks in DragDropContainer, ensuring falsy-but-valid IDs (e.g., 0) render overlays correctly and allowing custom drag-button aria labels.

Changes

Drag-Drop Accessibility and Correctness

Layer / File(s) Summary
Data Shape – dragButtonAriaLabel Prop
packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
DraggableProps gains an optional dragButtonAriaLabel?: string.
Component Implementation – ARIA Label Wiring
packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
Draggable reads dragButtonAriaLabel and conditionally passes it as an aria-label to DragButton when useDragButton is true; attributes/listeners forwarding remains.
Null-Safety Fixes – activeId Checks
packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx
Collision filtering, lastOverId fallback, handleDragOver guard, getDragOverlay early-return, and dragOverlay rendering checks changed from falsy checks (!activeId, activeId &&, lastOverId.current) to explicit nullish checks (activeId == null, activeId != null, lastOverId.current != null).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • nicolethoen
  • thatblindgeye
  • kmcfaul
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects both main changes: adding dragButtonAriaLabel support and fixing falsy id overlay rendering.
Linked Issues check ✅ Passed The PR fully implements both requirements from issue #12416: dragButtonAriaLabel prop forwarding to DragButton and explicit null comparisons for falsy numeric ids.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the two objectives in issue #12416; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented May 7, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx (1)

112-119: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Missed falsy-activeId check in collisionDetectionStrategy — same bug as lines 243/293.

Line 114 still uses activeId &&, which short-circuits to 0 (falsy) when activeId is the numeric value 0. This means the closestCenter path for container-level collision detection is skipped for any drag operation where activeId === 0, breaking multi-container sorting for items with that ID — the exact scenario this PR targets.

🐛 Proposed fix
-    if (activeId && activeId in items) {
+    if (activeId != null && activeId in items) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx`
around lines 112 - 119, The collisionDetectionStrategy callback incorrectly uses
"activeId && activeId in items", which treats numeric 0 as falsy and skips the
closestCenter branch; change that check to a null/undefined-safe test (e.g.
activeId != null or activeId !== null && activeId !== undefined) so 0 is treated
as a valid activeId, then proceed to call closestCenter with the filtered
droppableContainers as before (see collisionDetectionStrategy, activeId, items,
closestCenter, and args.droppableContainers.filter).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx`:
- Around line 112-119: The collisionDetectionStrategy callback incorrectly uses
"activeId && activeId in items", which treats numeric 0 as falsy and skips the
closestCenter branch; change that check to a null/undefined-safe test (e.g.
activeId != null or activeId !== null && activeId !== undefined) so 0 is treated
as a valid activeId, then proceed to call closestCenter with the filtered
droppableContainers as before (see collisionDetectionStrategy, activeId, items,
closestCenter, and args.droppableContainers.filter).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a459f5fa-c8ef-42c2-80a8-23f6f7a85b7f

📥 Commits

Reviewing files that changed from the base of the PR and between 4656548 and 5058508.

📒 Files selected for processing (2)
  • packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx

@logonoff logonoff force-pushed the 12416-dnd branch 2 times, most recently from c6d9241 to 6e11dbd Compare May 7, 2026 19:10
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx (1)

147-147: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missed falsy-0 fix on lastOverId.current.

This is the same bug class the PR is addressing. When lastOverId.current === 0, the truthy guard short-circuits to [] instead of returning [{ id: 0 }], breaking the collision-detection fallback for items with numeric ID 0.

🐛 Proposed fix
-      return lastOverId.current ? [{ id: lastOverId.current }] : [];
+      return lastOverId.current != null ? [{ id: lastOverId.current }] : [];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx` at
line 147, The return uses a truthy check that drops numeric id 0; update the
guard in the function inside DragDropContainer (the expression returning
lastOverId.current ? [{ id: lastOverId.current }] : []) to explicitly check for
null/undefined (e.g., lastOverId.current != null) so that 0 is treated as a
valid id and the collision-detection fallback returns [{ id: 0 }] when
appropriate.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx`:
- Line 147: The return uses a truthy check that drops numeric id 0; update the
guard in the function inside DragDropContainer (the expression returning
lastOverId.current ? [{ id: lastOverId.current }] : []) to explicitly check for
null/undefined (e.g., lastOverId.current != null) so that 0 is treated as a
valid id and the collision-detection fallback returns [{ id: 0 }] when
appropriate.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 07404410-6d19-4d51-80d8-3e80609e1200

📥 Commits

Reviewing files that changed from the base of the PR and between 5058508 and 6e11dbd.

📒 Files selected for processing (2)
  • packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx (1)

171-173: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Incomplete fix: !overId still silently drops drag-over events for items with id 0

handleDragOver guards with !overId on line 171, which short-circuits and returns early when overId === 0. If a consumer passes DraggableObject.id = 0, dragging over that item (or a container keyed 0) will be silently ignored, preventing container-move events from firing and leaving the item stuck. The identical falsy-id problem the PR fixes for activeId is still present here for overId.

🐛 Proposed fix
-    if (!overId || activeId in items) {
+    if (overId == null || activeId in items) {
       return;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx`
around lines 171 - 173, The guard in handleDragOver incorrectly uses "!overId"
which treats 0 as falsy and ignores valid IDs; change the check to explicitly
test for null/undefined (e.g., "overId == null" or "typeof overId ===
'undefined'") so ids of 0 are handled correctly, matching the existing fix
pattern used for activeId and ensuring container-move events fire for items
keyed with 0; update the conditional that currently reads "if (!overId ||
activeId in items) { return; }" to use the explicit null/undefined check for
overId.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx`:
- Around line 171-173: The guard in handleDragOver incorrectly uses "!overId"
which treats 0 as falsy and ignores valid IDs; change the check to explicitly
test for null/undefined (e.g., "overId == null" or "typeof overId ===
'undefined'") so ids of 0 are handled correctly, matching the existing fix
pattern used for activeId and ensuring container-move events fire for items
keyed with 0; update the conditional that currently reads "if (!overId ||
activeId in items) { return; }" to use the explicit null/undefined check for
overId.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6cecdc4e-0fc3-42ce-ae64-ef933a90c6fb

📥 Commits

Reviewing files that changed from the base of the PR and between 6e11dbd and a42b543.

📒 Files selected for processing (2)
  • packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-drag-drop/src/components/DragDrop/Draggable.tsx

…y 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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - [DragDropSort / DragButton] - aria-label is not customizable and not translatable

2 participants