Introduce inheritDirectives: false
#480
Replies: 2 comments 1 reply
-
|
I like the idea! |
Beta Was this translation helpful? Give feedback.
-
|
1 year after. If anyone else has suggestion on how to make the description better to create more "buzz" let me know. Note that even customising the directive to target a specific element via More demos:
Common valid criticisms
Final thoughtsI know that there are alternatives for every pattern listed, but a framework provides convenience, that's why we use them primarily. If this is not viable, I think we can safely close this thread. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Curious to check the community pulse on this, since I do not have enough knowledge of
@vuecore code to understand the implications of such an idea or even if it's feasible so bear with me, please.One thing that broke a lot of my tests while migrating to
vue@3was that I relied upon heavily — almost 100% — on av-test="'some-id'"directive to target my elements and components. The only thing this directive does is conditionally adddata-test-idattribute when!production.With the
vue@2single root node limitation, directives declared on the components always "found a way to fall through" into the root element. Withvue@3that's no longer the case and directives are ignored if the multi-root node or if root node does not render an element (directly). For the first scenario, it makes total sense, vue could not simply guess which element I wanted. In the second scenario, there is a nuance: I can still render a single node element, but not directly. Some of my components haverenderless/providerwrappers as the root element and the actual element node is passed to its slot. In those scenarios the directive declared on the component would still fallthrough correctly invue@2and now it doesn't.Example
and in context
Idea
The idea is to give a more or less similar treatment to
$attrsand allow to forward directives declared on the component to a desired element node:v-bind="$directives"property which would be a map of all passed directives.$directivesin this scenario would be prefixed with some internal identifiable string, the same way that listeners are prefixed with "on"onX. Since thev-bind=idea, would require tweaking the parsing ofv-bindcontents, an alternative idea be a new directive:v-bind-directivesorv-directives.<!-- VDialog.vue --> <template> <!-- renderless accessibility provider for dialogs --> <a11y-dialog-renderless #default="{ backdropRef, dialogRef, titleRef, closeRef, focusRef }" @close="$emit('close')" > - <div class="dialog-root"> + <div class="dialog-root" v-bind="$directives"> <div v-bind="backRef" /> <div v-bind="dialogRef"> <!-- you get the point --> </div> </div> </a11y-dialog> </template> <script> export default { + // if fallthrough behaviour is still a thing by that time + inheritDirectives: false } </script>$attrsthat get their companionuseAttrs()function, in a purecomposition-apiscenario we could also have:useDirectives()composable to return the provided directives map for binding.directivescould be destructured fromsetup()hook context, in a similar fashionIs it too absurd? Is it just me? Note: I know that there are plenty of ways to work around this particular problem (manually adding a
data-test-idand using$attrsand then tweak the compiler config to remove them but that's not the point. There are plenty of other examples that are not as easy to solve as this one, like the O.G custom directive demov-focusfor a component that does not render the<input>as root.Anyways, just an idea! Cheers 👋
Beta Was this translation helpful? Give feedback.
All reactions