Skip to content

Allow custom toggles in vue/require-toggle-inside-transition #2535

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

Closed
cjpearson opened this issue Aug 27, 2024 · 4 comments · Fixed by #2537
Closed

Allow custom toggles in vue/require-toggle-inside-transition #2535

cjpearson opened this issue Aug 27, 2024 · 4 comments · Fixed by #2537

Comments

@cjpearson
Copy link
Contributor

cjpearson commented Aug 27, 2024

What rule do you want to change?

vue/require-toggle-inside-transition

Does this change cause the rule to produce more or fewer warnings?

If option is configured, fewer warnings.

How will the change be implemented? (New option, new default behavior, etc.)?

I would add a new option to the rule which allows adding additional custom "toggle" directives which will satisfy this check in addition to v-show or v-if.

Please provide some example code that this change will affect:

<transition>
  <dialog v-dialog="visible">...</dialog>
</transition>

What does the rule currently do for this code?

It flags it as an error, because there is no v-show or v-if on the <dialog>

What will the rule do after it's changed?

If the rule is configured to include v-dialog as a toggle directive, it will no longer flag this case as an error.

Additional context

In the example above, v-dialog is a custom directive which shows/hides the element using close() and showModal(). Transitions are also applied in the directive.

@FloEdelmann
Copy link
Member

Transitions are also applied in the directive.

Is this documented somewhere? If not, it may be a bug or accidental behavior that might change in the future, and then I don't think we should encourage people to use that.

@cjpearson
Copy link
Contributor Author

That's a good question. I wrote this code some time ago and can't remember exactly where I found this pattern. 😅 It may have been from mimicking v-show.

The transition behavior is intentional though. The directive reads the transition property of the vnode and calls the hooks when necessary. e.g.

mounted(el, { value, modifiers }, { transition }) {
  if (transition && value) {
    transition.enter(el)
  }
  toggleDialog(el, value, modifiers.modal)
},

@FloEdelmann
Copy link
Member

Okay, I guess it's fine then. A PR is welcome that:

  • adds a new option additionalDirectives: string[] to the rule
  • updates the docs
  • adds new test cases

@cjpearson
Copy link
Contributor Author

Cool, thanks for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants