Skip to main content

Radial Menu Spell

The RadialMenuSpell component creates a beautiful circular menu that appears at the cursor position, perfect for providing quick contextual actions. It features smooth animations, visual feedback, and supports both keyboard and mouse activation. Radial Menu Demo

Features

  • Circular Layout: Items arranged in a circle for equal access
  • Visual Feedback: Animated hover states and selection indicators
  • Cancel Zone: Center area for canceling without action
  • Flexible Activation: Supports keyboard shortcuts and mouse events
  • Hold-to-Select: Natural interaction pattern for quick actions
  • Escape Support: Press ESC to cancel without executing
  • Theme Integration: Adapts to Cedar’s light/dark mode
  • Icon Support: Use emojis or Lucide icons for menu items

Installation

Basic Usage

Props

RadialMenuSpell Props

RadialMenuItem Interface

Activation Patterns

The most natural interaction for radial menus is the hold pattern:
User flow:
  1. Right-click and hold to open menu
  2. Move mouse to desired item (it highlights)
  3. Release to execute action
  4. Or move to center and release to cancel

Toggle Pattern

For persistent menus that stay open:
User flow:
  1. Press Space to open menu
  2. Move mouse to select item
  3. Click to execute or press Space again to close

Keyboard Shortcut

Bind to any keyboard shortcut:

Advanced Examples

AI Actions Menu

Create an AI-powered context menu:

Emoji-Based Menu

Use emojis for a playful interface:

Dynamic Menu Items

Generate menu items based on context:

Visual Customization

The radial menu automatically adapts to Cedar’s styling system:

Theme Integration

The component uses Cedar’s styling context:
  • Brand Color: Used for hover states and selection
  • Dark Mode: Automatically adjusts colors and contrasts
  • Text Colors: Adapts based on theme

Layout Constants

The component uses these layout constants (defined in the component):

Interaction Details

Mouse Behavior

  • Hover: Moving mouse over items highlights them
  • Center Zone: Moving to center shows “Cancel”
  • Selection: Release (hold mode) or click (toggle mode) to select
  • Visual Feedback: Animated ring shows current selection

Keyboard Support

  • ESC: Cancel without executing any action
  • Activation Keys: Defined by activationConditions

Position Handling

  • Mouse Events: Menu appears at cursor position
  • Keyboard Events: Menu appears at viewport center
  • Smart Positioning: Stays within viewport bounds

Best Practices

1. Limit Item Count

Keep menus focused with 3-8 items:

2. Use Clear Icons

Choose recognizable icons:

3. Consistent Actions

Keep onInvoke callbacks focused:

4. Handle Errors Gracefully

Accessibility Considerations

While the radial menu is primarily a visual component, consider these accessibility aspects:
  1. Alternative Activation: Provide keyboard shortcuts as alternatives
  2. Clear Labels: Use descriptive titles for screen readers
  3. Escape Route: Always allow ESC key to cancel
  4. Visual Contrast: The component respects Cedar’s theme for proper contrast

Performance Notes

  • Singleton Management: Uses Cedar’s spell system for efficient event handling
  • Animation Performance: Uses CSS transforms for smooth animations
  • Memory Efficient: Automatically cleaned up when component unmounts
  • Event Delegation: Single set of listeners for all instances

Common Patterns

Tool Selection Menu

Media Controls

Troubleshooting

  • Check that the spell ID is unique
  • Verify activation conditions are correct
  • Ensure component is mounted

Items not executing

  • Verify onInvoke callbacks are defined
  • Check for errors in callback functions
  • Ensure Cedar store is accessible

Visual issues

  • Component adapts to Cedar’s theme automatically
  • Check that Cedar styling context is provided
  • Verify Container3D component is available