1212
fix: keyboard accessibility in Content-Type Builder field actions by dev-shahed · Pull Request #24566 · strapi/strapi · GitHub
Skip to content

fix: keyboard accessibility in Content-Type Builder field actions#24566

Merged
HichamELBSI merged 1 commit intostrapi:developfrom
dev-shahed:fix/content-type-builder-keyboard-accessibility
Oct 14, 2025
Merged

fix: keyboard accessibility in Content-Type Builder field actions#24566
HichamELBSI merged 1 commit intostrapi:developfrom
dev-shahed:fix/content-type-builder-keyboard-accessibility

Conversation

@dev-shahed
Copy link
Copy Markdown
Contributor

@dev-shahed dev-shahed commented Oct 12, 2025

Fix Keyboard Accessibility in Content-Type Builder

Issue Validated ✅

The reported accessibility issue exists in the Content-Type Builder. Keyboard and screen reader users cannot activate the Edit and Delete buttons for fields in the field list.

Root Cause

  1. Event Handler Type Mismatch: The handleDelete event handler was typed as React.MouseEvent, which doesn't accept keyboard events.
  2. Missing Keyboard Event Handlers: The Edit and Delete IconButton components didn't have explicit onKeyDown handlers to handle Enter and Space key presses.
  3. Missing Keyboard Sensor: The drag-and-drop functionality only used PointerSensor, making it inaccessible to keyboard users.

Changes Made

1. AttributeRow.tsx (packages/core/content-type-builder/admin/src/components/AttributeRow.tsx)

Updated Event Handler Types

  • Changed handleDelete to accept both React.MouseEvent | React.KeyboardEvent
  • Changed handleClick to accept both React.MouseEvent | React.KeyboardEvent (optional parameter)

Added Keyboard Event Handlers

  • Added handleEditKeyDown: Listens for Enter or Space key and triggers handleClick
  • Added handleDeleteKeyDown: Listens for Enter or Space key and triggers handleDelete

Updated IconButtons

  • Added onKeyDown={handleEditKeyDown} to Edit IconButton
  • Added onKeyDown={handleDeleteKeyDown} to Delete IconButton

2. List.tsx (packages/core/content-type-builder/admin/src/components/List.tsx)

Added Keyboard Support for Drag and Drop

  • Imported KeyboardSensor and sortableKeyboardCoordinates from @dnd-kit
  • Updated sensors configuration to include both PointerSensor and KeyboardSensor
  • Used sortableKeyboardCoordinates for proper sortable keyboard navigation

Testing Performed

yarn lint - All checks passed
yarn setup - Build completed successfully
✅ Code follows existing patterns from useKeyboardDragAndDrop hook

Expected User Impact

After this fix:

  • ✅ Keyboard users can press Enter or Space on the Edit button to open the edit modal
  • ✅ Keyboard users can press Enter or Space on the Delete button to delete a field
  • ✅ Keyboard users can use arrow keys to reorder fields via drag and drop
  • ✅ Screen readers will properly announce button actions
  • ✅ Full WCAG 2.1 compliance for keyboard navigation

How to test

  1. Navigate to Content-Type Builder
  2. Create or open a content type with at least one field
  3. Using only keyboard:
    • Tab to the Edit button on a field
    • Press Enter or Space - the edit modal should open ✅
    • Tab to the Delete button on a field
    • Press Enter or Space - the delete confirmation should appear ✅
    • Focus on the Drag button and use arrow keys to reorder fields ✅

Testing with Screen Reader

  1. Enable a screen reader (NVDA/JAWS on Windows, VoiceOver on Mac)
  2. Navigate to Content-Type Builder field list
  3. Verify buttons are announced correctly
  4. Verify Enter/Space keys activate buttons

Screenshots/Videos

Related issue(s)/PR(s) #24565

Let us know if this is related to any issue/pull request

@strapi-cla
Copy link
Copy Markdown

strapi-cla commented Oct 12, 2025

CLA assistant check
All committers have signed the CLA.

@vercel
Copy link
Copy Markdown

vercel bot commented Oct 12, 2025

@dev-shahed is attempting to deploy a commit to the Strapi Team on Vercel.

A member of the Team first needs to authorize it.

@dev-shahed
Copy link
Copy Markdown
Contributor Author

dev-shahed commented Oct 13, 2025

Hi maintainers 👋
I’ve completed the requested changes. Could you please review and approve when you have a moment?

@oiorain oiorain added source: core:content-type-builder Source is core/content-type-builder package pr: fix This PR is fixing a bug version: 5 Issue is present in Strapi 5 community Changes and fixes created by community members labels Oct 13, 2025
Comment thread packages/core/content-type-builder/admin/src/components/AttributeRow.tsx Outdated
HichamELBSI
HichamELBSI previously approved these changes Oct 13, 2025
Copy link
Copy Markdown
Contributor

@HichamELBSI HichamELBSI left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @dev-shahed!

@HichamELBSI
Copy link
Copy Markdown
Contributor

HichamELBSI commented Oct 13, 2025

@dev-shahed There are some issues with the commit message, please make it short (< 100 characters). And make sure to squash your commits as well please.

@HichamELBSI HichamELBSI merged commit 7969a45 into strapi:develop Oct 14, 2025
49 of 50 checks passed
@dev-shahed
Copy link
Copy Markdown
Contributor Author

dev-shahed commented Oct 14, 2025

@dev-shahed There are some issues with the commit message, please make it short (< 100 characters). And make sure to squash your commits as well please.

@HichamELBSI Thanks for merging! Appreciate your time reviewing it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Changes and fixes created by community members hacktoberfest-accepted pr: fix This PR is fixing a bug source: core:content-type-builder Source is core/content-type-builder package version: 5 Issue is present in Strapi 5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants