--- title: Use .exact Modifier for Precise Keyboard/Mouse Shortcuts impact: MEDIUM impactDescription: Without .exact, shortcuts fire even when additional modifier keys are pressed, causing unintended behavior type: best-practice tags: [vue3, events, keyboard, modifiers, shortcuts, accessibility] --- # Use .exact Modifier for Precise Keyboard/Mouse Shortcuts **Impact: MEDIUM** - By default, Vue's modifier key handlers (`.ctrl`, `.alt`, `.shift`, `.meta`) fire even when other modifier keys are also pressed. Use `.exact` to require that ONLY the specified modifiers are pressed, preventing accidental triggering of shortcuts. ## Task Checklist - [ ] Use `.exact` when you need precise modifier combinations - [ ] Without `.exact`: `@click.ctrl` fires for Ctrl+Click AND Ctrl+Shift+Click - [ ] With `.exact`: `@click.ctrl.exact` fires ONLY for Ctrl+Click - [ ] Use `@click.exact` for plain clicks with no modifiers **Incorrect:** ```html ``` ```html ``` **Correct:** ```html ``` ```html ``` ```html ``` ## Behavior Comparison ```javascript // WITHOUT .exact @click.ctrl="handler" // Fires when: Ctrl+Click, Ctrl+Shift+Click, Ctrl+Alt+Click, Ctrl+Shift+Alt+Click // Does NOT fire: Click (without Ctrl) // WITH .exact @click.ctrl.exact="handler" // Fires when: ONLY Ctrl+Click // Does NOT fire: Ctrl+Shift+Click, Ctrl+Alt+Click, Click // ONLY .exact (no other modifiers) @click.exact="handler" // Fires when: Plain click with NO modifiers // Does NOT fire: Ctrl+Click, Shift+Click, Alt+Click ``` ## Practical Example: File Browser Selection ```vue ``` ## Keyboard Shortcuts with .exact ```html ``` ## Reference - [Vue.js Event Handling - .exact Modifier](https://vuejs.org/guide/essentials/event-handling.html#exact-modifier)