Skip to content
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

Added exact as valid modifier #269

Merged
merged 1 commit into from
Dec 2, 2017
Merged

Conversation

mokkabonna
Copy link
Contributor

@mysticatea
Copy link
Member

mysticatea commented Dec 1, 2017

Thank you for the PR!

The exact modifier seems to have to use with one or more system modifiers. Could you add the check the exact modifier is used with system modifiers?

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."
           })
         }

@mokkabonna
Copy link
Contributor Author

mokkabonna commented Dec 1, 2017

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:

The .exact modifier should be used in combination with other system modifiers to indicate that the exact combination of modifiers must be pressed for the handler to fire.

But I have manually tested this and both handlers in the first example are triggered when holding ctrl.

@mysticatea
Copy link
Member

Oh, thank you for the explanation! I got it. LGTM.

@mokkabonna
Copy link
Contributor Author

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.

Copy link
Member

@michalsnik michalsnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mokkabonna ! LGTM 👍

@michalsnik michalsnik merged commit b8a325d into vuejs:master Dec 2, 2017
@mokkabonna mokkabonna deleted the exact-modifier branch December 20, 2017 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants