21

Complex Modifiers

Advanced .with_() modifier patterns for event handling

Event Modifiers

Using .with_() to modify event behavior with prevent, stop, debounce, throttle

Prevent Default & Stop Propagation

🎯 What these modifiers do:

  • prevent=True → Stops browser's default action (form submit, link navigation, etc.)
  • stop=True → Stops event from bubbling up to parent elements

Try submitting this form - it won't reload the page:

✅ Check console: Form data logged but page didn't reload!

Without prevent=True, the form would submit and reload/navigate away


Click the inner element to see stop propagation in action:

Outer container (click me) → logs 'Outer clicked'
Inner element (click me) → logs 'Inner clicked' ONLY

✓ Clicking inner element won't trigger outer's click handler

Throttling for Performance

Clicks registered:

âš¡ Throttled to 1 click per second maximum

Use throttle for: API calls, scroll events, resize handlers

Keyboard Modifiers

Handle specific key combinations and keyboard events

Key-Specific Handlers

Last key:

Advanced Modifier Patterns

Using multiple modifiers together for complex interactions

Special Event Modifiers

Modifiers that control how and when events fire

The 'once' modifier ensures the event only fires on first click

Scroll me! (with passive listener for better performance)

Line 0

Line 1

Line 2

Line 3

Line 4

Line 5

Line 6

Line 7

Line 8

Line 9

Line 10

Line 11

Line 12

Line 13

Line 14

Line 15

Line 16

Line 17

Line 18

Line 19

Scroll position: px

Passive listeners improve scroll performance by not blocking the browser

Combining multiple modifiers for robust form handling

Submit count:

Last submit:

Form uses prevent on submit event, button uses throttle for rate limiting

Form Validation with Modifiers

Validating input and controlling form submission

Click outside the field to validate

Processing your submission...
💡 This example shows:
  • Validation on blur (when you click out)
  • Conditional submission based on validation
  • Loading state only for valid submissions

Real-World Patterns

Practical modifier combinations you'll use in real applications

Auto-Save Pattern

Status:

Perfect for: Blog editors, note-taking apps, form drafts

Move your mouse over this area

Mouse: x=, y=

Best Practices