Skip to main content

Questioning Spell

The QuestioningSpell component transforms your cursor into an interactive exploration tool that reveals hidden information when hovering over elements. It’s perfect for creating educational interfaces, providing contextual help, or building discovery-based experiences.

Features

  • Interactive Cursor: Custom reticle cursor with smooth animations
  • Data Attribute Detection: Automatically finds data-question attributes
  • Visual Feedback: Rotating reticle that locks onto targets
  • Tooltip Display: Shows contextual information on hover
  • Theme Aware: Adapts to Cedar’s color scheme
  • Keyboard Activation: Default ‘Q’ key toggle

Installation

Basic Usage

Press ‘Q’ to activate the questioning mode, then hover over elements to see their explanations.

Props

Customization

Custom Activation

Change the activation key or mode:

Hold Mode

Use hold mode for temporary activation:

Multiple Triggers

Support multiple activation methods:

Advanced Examples

Educational Interface

Create an educational UI with detailed explanations:

Dashboard with Metrics

Add context to complex data visualizations:

Form with Field Help

Provide inline help for form fields:

Dynamic Questions

Generate questions based on data:

Visual Behavior

Cursor States

The questioning cursor has two visual states:
  1. Searching State: Continuously rotating reticle when not hovering over a target
  2. Locked State: Snaps to nearest 180° and scales slightly when hovering over an element with data-question

Animation Details

  • Rotation Speed: 3 seconds per full rotation when searching
  • Lock Animation: Spring animation with bounce when locking onto target
  • Debounce: 200ms delay before releasing lock to prevent flicker

Theme Integration

The cursor automatically uses Cedar’s theme colors:
  • Uses styling.color from Cedar store for the reticle color
  • Falls back to #3b82f6 (blue) if no color is set
  • Tooltip background matches the theme color

Best Practices

1. Write Clear Explanations

2. Keep Tooltips Concise

3. Add Context Where Needed

4. Use for Progressive Disclosure

Technical Implementation

How It Works

  1. Activation: User presses ‘Q’ (or custom key) to activate
  2. Event Listening: Listens to mousemove events when active
  3. Element Detection: Uses Element.closest('[data-question]') to find attributes
  4. Tooltip Display: Shows tooltip with the attribute value
  5. Cursor Enhancement: Uses motion-plus-react for smooth cursor animations

Performance Considerations

  • Event Delegation: Single mousemove listener for all elements
  • Debounced Animations: Prevents excessive re-renders
  • Conditional Rendering: Only renders when spell is active
  • Ref-based State: Uses refs for animation values to avoid re-renders

Styling

Custom Tooltip Styles

While the component provides a default tooltip, you can customize it:

Cursor Customization

The cursor consists of corner brackets that form a reticle:

Accessibility

Keyboard Navigation

  • The spell can be activated via keyboard (default: ‘Q’)
  • Consider providing alternative ways to access the same information

Screen Reader Support

For better accessibility, consider also providing the information in screen-reader accessible ways:

Alternative Access

Provide multiple ways to access help information:

Troubleshooting

Tooltip not appearing

  • Verify data-question attribute is set correctly
  • Check that the spell is activated (press ‘Q’)
  • Ensure QuestioningSpell component is mounted

Cursor not changing

  • Check motion-plus-react is installed and configured
  • Verify no CSS conflicts with cursor styles
  • Ensure spell activation is working

Performance issues

  • Reduce the number of elements with data-question if excessive
  • Consider lazy-loading content with many questionable elements
  • Check for memory leaks in tooltip content generation