-
-
Notifications
You must be signed in to change notification settings - Fork 681
Added exact as valid modifier #269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for the PR! The For example: const SYSTEM_MODIFIERS = new Set([
'ctrl', 'alt', 'shift', 'meta'
})
// ....
if (modifier === "exact" && !node.key.modifiers.some(SYSTEM_MODIFIERS.has, SYSTEM_MODIFIERS)) {
context.report({
node,
loc: node.loc,
message: "The 'exact' modifier should be used in combination with other system modifiers."
})
} |
It's not only for system modifiers. If I have this: <div @click.ctrl.exact="handler1" @click="handler2"></div> handler 2 will be also be triggered when holding ctrl. handler 1 will only be triggered when holding ctrl. Using exact on both works as expected: <div @click.ctrl.exact="handler1" @click.exact="handler2"></div> But I agree the docs give the impression that you got:
But I have manually tested this and both handlers in the first example are triggered when holding ctrl. |
Oh, thank you for the explanation! I got it. LGTM. |
Just as a follow up: This code generates the guard: https://github.com/vuejs/vue/blob/daed1e73557d57df244ad8d46c9afff7208c9a2d/src/compiler/codegen/events.js#L81 It starts with all modifier keys and removes any that are present. So if none are present then the guard generates this: if (
$event.ctrlKey ||
$event.shiftKey ||
$event.altKey ||
$event.metaKey
) {
return null
} So if any modifier present, it does not trigger the handler. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mokkabonna ! LGTM 👍
https://vuejs.org/v2/guide/events.html#exact-Modifier