Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(dropdown-menu): add blueprint migration documentation #3927

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
331 changes: 331 additions & 0 deletions notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,331 @@
# Box UI Elements DropdownMenu to Blueprint DropdownMenu Component Mapping

## Component Architecture

[previous content remains unchanged...]

## Core Props Mapping

[previous content remains unchanged...]

## Accessibility and Keyboard Navigation

[previous content remains unchanged...]

## Positioning System

[previous content remains unchanged...]

## Additional Considerations

### Migration Notes

- Component Structure:

- Blueprint requires explicit component composition
- Need to split single DropdownMenu into multiple components
- More maintainable and reusable architecture
- Better separation of concerns
- Improved component isolation

- State Management:

- Transition from internal state to controlled/uncontrolled modes
- Simplified event handling through unified callbacks
- Better state predictability
- Improved debugging capabilities

- Accessibility Improvements:
- Built-in WAI-ARIA compliance
- Better screen reader support
- Enhanced keyboard navigation
- Automatic focus management
- Improved aria attributes

### Type Safety

- TypeScript Benefits:

- Full TypeScript support out of the box
- Strict prop type checking
- Better IDE integration
- Improved code completion
- Runtime type checking removed
- Better error detection during development

- Component Types:
- More granular component typing
- Better prop validation
- Improved type inference
- Enhanced component composition
- Better generic support

### Performance

- Portal Management:

- Improved portal handling through Radix UI
- Better z-index management
- Reduced DOM manipulation
- More efficient rendering

- Rendering Optimizations:

- Reduced re-renders through Radix UI
- Better state batching
- Improved event delegation
- More efficient positioning updates
- Better memory management

- Animation Performance:
- Hardware-accelerated animations
- Smoother transitions
- Better frame rates
- Reduced layout thrashing

### Future Considerations

- Progressive Migration:

- Can be migrated component by component
- Backward compatibility possible
- Gradual adoption strategy
- Minimal disruption to existing code

- Testing Strategy:
- Enhanced testing capabilities
- Better component isolation
- Improved accessibility testing
- More reliable visual regression tests
- Better integration testing support
[previous content remains unchanged...]

## Core Props Mapping

[previous content remains unchanged...]

## Accessibility and Keyboard Navigation

[previous content remains unchanged...]

## Positioning System

### Box UI Elements (TetherComponent)

- Positioning Props:
- attachment: 'top left' | 'top right' | etc.
- targetAttachment: 'bottom left' | 'bottom right' | etc.
- constraints: Array of positioning rules
```javascript
constraints: [
{
to: 'scrollParent' | 'window',
attachment: 'together',
pin: boolean,
},
];
```
- Manual positioning calculation
- Complex constraint system
- Less intuitive positioning configuration

### Blueprint (Radix UI Positioning)

- Positioning Props:

- side: 'top' | 'right' | 'bottom' | 'left'
- align: 'start' | 'center' | 'end'
- avoidCollisions: boolean
- collisionPadding: number | Padding
- sticky: 'partial' | 'always'
- sideOffset: number
- alignOffset: number

- Benefits:
- More semantic positioning system
- Automatic collision detection
- Better viewport containment
- Simpler configuration
- Built-in animations
- Improved performance
- Better handling of dynamic content

### Migration Considerations

- TetherComponent to Radix UI transition:
- Different positioning terminology
- Simpler constraint system
- More predictable behavior
- Better performance characteristics
- Improved accessibility integration
[previous content remains unchanged...]

## Core Props Mapping

[previous content remains unchanged...]

## Accessibility and Keyboard Navigation

### WAI-ARIA Menu Button Pattern Implementation

- Box UI Elements:

- Manual ARIA attribute management
- Basic WAI-ARIA menu button compliance
- Custom keyboard navigation implementation
- Manual focus management

- Blueprint/Radix UI:
- Built-in WAI-ARIA menu button compliance
- Comprehensive ARIA attribute handling
- Enhanced keyboard navigation
- Automatic focus management
- Better screen reader support

### Keyboard Navigation

- Box UI Elements:

- Space/Enter: Toggle menu
- Arrow Right: Open menu
- Arrow Down: Open menu and focus first item
- Arrow Up: Open menu and focus last item
- Escape: Close menu
- Manual focus trap implementation

- Blueprint:
- Space/Enter: Open menu and focus first item
- Arrow Down: Open menu and focus first item
- Arrow Up: Open menu and focus last item
- Arrow Right: Open submenu
- Arrow Left: Close submenu
- Escape: Close menu
- Home: Focus first item
- End: Focus last item
- Type character: Move to matching item
- Automatic focus trap management

### Focus Management

- Box UI Elements:

- Manual focus management through refs
- Custom focus trap implementation
- Manual focus restoration
- Document click handlers for blur

- Blueprint:
- Automatic focus management through Radix UI
- Built-in focus trap
- Automatic focus restoration
- Better handling of nested focus contexts
- Improved focus restoration on menu close
[previous content remains unchanged...]

## Core Props Mapping

### Box UI Elements Props -> Blueprint Equivalent

1. bodyElement (HTMLElement) -> container (HTMLElement)

- Maps to DropdownMenuPortal's container prop
- Both control where menu content is rendered
- Blueprint provides more flexible portal handling

2. children (React.Node) -> Split across components

- First child -> DropdownMenuTrigger children
- Second child -> DropdownMenuContent children
- Blueprint requires explicit component structure
- Improves component composition and reusability

3. constrainToScrollParent (boolean) -> collisionBoundary (Boundary)

- Maps to DropdownMenuContent's collisionBoundary
- Different approach to scroll parent containment
- Blueprint offers more granular collision control

4. constrainToWindow (boolean) -> avoidCollisions (boolean)

- Maps to DropdownMenuContent's avoidCollisions
- Blueprint handles collision avoidance automatically
- More robust positioning system through Radix UI

5. constrainToWindowWithPin (boolean) -> sticky (boolean)

- Maps to DropdownMenuContent's sticky prop
- Controls whether menu stays within viewport
- Blueprint provides better viewport containment

6. isResponsive (boolean) -> No direct equivalent

- Blueprint handles responsive behavior automatically
- Uses modern CSS features for responsiveness
- Consider using CSS media queries instead

7. isRightAligned (boolean) -> align="end" (string)

- Maps to DropdownMenuContent's align prop
- Blueprint offers more alignment options
- More semantic alignment system

8. onMenuClose (function) -> onOpenChange (function)

- Maps to DropdownMenuRoot's onOpenChange
- Blueprint uses single handler for open/close
- Provides event object with more context

9. onMenuOpen (function) -> onOpenChange (function)

- Maps to DropdownMenuRoot's onOpenChange
- Blueprint consolidates state management
- More consistent event handling

10. tetherAttachment (string) -> side, align (string)

- Maps to DropdownMenuContent's positioning props
- Blueprint uses more semantic positioning system
- More intuitive and flexible positioning options

11. tetherTargetAttachment (string) -> side, align (string)

- Maps to DropdownMenuContent's positioning props
- Blueprint simplifies positioning configuration
- Better defaults and automatic positioning

12. useBubble (boolean) -> modal (boolean)
- Maps to DropdownMenuRoot's modal prop
- Controls event propagation behavior
- Blueprint provides better event isolation

- Box UI Elements: Single DropdownMenu component

- Combines trigger and menu content in a single component
- Uses TetherComponent for positioning
- Manages its own state and focus handling
- Requires exactly two children: button and menu
- Handles keyboard navigation and accessibility internally
- Manages document click handlers for menu closing

- Blueprint: Composable components based on Radix UI primitives
- DropdownMenuRoot: Controls overall state and behavior
- Manages open/close state
- Handles event delegation
- Controls modal behavior
- DropdownMenuTrigger: Handles button/trigger element
- Manages button accessibility attributes
- Controls focus states
- DropdownMenuContent: Manages menu content and positioning
- Handles collision detection
- Controls menu alignment and positioning
- Manages portal rendering
- DropdownMenuPortal: Controls rendering container
- Handles menu content portaling
- Manages z-index stacking
- Additional utility components:
- DropdownMenuSeparator: Visual dividers
- DropdownMenuGroup: Logical grouping
- DropdownMenuRadioGroup: Radio selection groups
- DropdownMenuCheckboxItem: Checkbox items
- DropdownMenuRadioItem: Radio items
- DropdownMenuSubMenu components: Nested menu support
Loading