attributes that are not defined as props are not converted from camelCase to kebap-case #14365
Replies: 1 comment
-
|
@Fuzzyma this is a real bug in how the root cause is in p.name = camelize(p.name)so the problem is in the runtime: Vue has a workaround for now: destructure the scope and bind explicitly: <template #trigger="scope">
<button :data-testid="scope.dataTestid" :aria-controls="scope.ariaControls">
Trigger
</button>
</template>or use a helper: this should probably be filed as a bug. the compiler camelizes but the runtime never hyphenates back for HTML attributes. |
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.
-
I came across this today and wonder if this is really intended.
Every attribute name that is not defined as prop is just converted to lowercase when applied to the component.
So things like
ariaControlsbecomeariacontrolsinstead ofaria-controlsHowever this does not happen, if the attrubute falls through and hits another component that does define it as prop. I guess this happens because setAttribute ultimately just lowercases the attribute when it hits an html element but otherwise just passes it though as i.
So here are some examples:
However, when we define it as prop it obviosuly is passed correctly because vue converts forth and back:
So, just dont write
dataTestidon html then you might ask...Well, all this wouldnt be a problem if it woulnt convert all things passed to a slot to camelCase:
Menu.vue
Every thing you pass to
<slot>is converted to camelCase. Soscopeonly containsdataTestidandariaControls. But when I now v-bind it to the button, it breaks the html attributes.I suspect not a lot of people come across this since attributes with hyphens are rare and mostly aria or data.
So my big question is: is this intended? It feels very wrong to me at least.
And if it is intended, why? And could there be an exception for data and aria attributes?
Beta Was this translation helpful? Give feedback.
All reactions