--- title: Click Events on Custom Components Require Emit or Fallthrough impact: HIGH impactDescription: Native click events on custom components won't work without proper emit declaration or attribute fallthrough type: gotcha tags: [vue3, events, components, emit, click, migration] --- # Click Events on Custom Components Require Emit or Fallthrough **Impact: HIGH** - Unlike native HTML elements, custom Vue components don't automatically forward native DOM events like `click`. You must either emit the event explicitly, rely on attribute fallthrough to a single root element, or use the `.native` modifier (Vue 2 only, removed in Vue 3). This is a common source of confusion and migration issues. ## Task Checklist - [ ] Declare emitted events using `defineEmits` in child components - [ ] Emit click events from child component when needed - [ ] Understand that single-root components automatically forward attrs to root - [ ] Remove `.native` modifier when migrating from Vue 2 to Vue 3 - [ ] For multi-root components, explicitly bind `$attrs` or emit events **Incorrect:** ```html ``` ```html ``` ```html ``` **Correct:** ```html ``` ```html ``` ```html ``` ## Component Events Don't Bubble ```javascript // Important: Component-emitted events do NOT bubble // You can only listen to events from direct children // WRONG: Trying to catch grandchild events // CORRECT: Each level must relay the event ``` ## Vue 3 Native Event Behavior ```javascript // In Vue 3, if you declare an event in emits: defineEmits(['click']) // Then @click on the component ONLY listens to emitted events // NOT native click events // If you don't declare 'click' in emits: defineEmits(['custom-event']) // Then @click on single-root component will: // 1. Fall through to root element as native listener // 2. Fire on native click ``` ## Composition API Emit Pattern ```vue ``` ## Migration from Vue 2 ```html ``` ## Reference - [Vue.js Component Events](https://vuejs.org/guide/components/events.html) - [Vue.js Fallthrough Attributes](https://vuejs.org/guide/components/attrs.html) - [Vue 3 Migration - .native Modifier Removed](https://v3-migration.vuejs.org/breaking-changes/v-on-native-modifier-removed.html)