-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
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
[feature request] new v-slot
syntax does not support slot names that start with a square bracket [
or names with spaces
#10390
Comments
v-slot
syntax does not support slot names that start with a square bracket [
v-slot
syntax does not support slot names that start with a square bracket [
v-slot
syntax does not support slot names that start with a square bracket [
v-slot
syntax does not support slot names that start with a square bracket [
Unfortunately, brackets are for dynamic slot names: https://vuejs.org/v2/guide/components-slots.html#Dynamic-Slot-Names so you will have to use a different naming convention |
@posva will using a name such as |
I would've expected a bracketed string literal to work, but it appears the parser doesn't like that: <component>
<template v-slot:['[foo][bar]']>TEST</template>
</component> |
@sirlancelot it works with backticks though (see my example), maybe it should be documented? |
quotes seems to be forbidden. Since they can be used to delimiter value in html attributes ( Personally I wouldn't use a name for a slot if it cannot be used as a variable name. It also makes it easier to access them through |
@posva For reference, here is our use case of the slot names which are determined at runtime: https://bootstrap-vue.netlify.com/docs/components/table#custom-data-rendering Note that we are using render functions internally to generate the table cells. Users provide a list of "fields" for their table, and we look to see if the user has provided a slot for that field to do custom rendering on the cell. Note that each field name could contain dot (in the case the field's key points to a nested object value in the table row), underscores, letters, numbers (and in some cases spaces... anything that can be used as an object property key) |
You should use scoped slots. |
@Justineo we are using scoped slots (we are providing the scoped slots to consumers, and the consumers use these slots to place their custom formatting in). The issue is that the slot names are defined by the consumer, following a particular naming convention. As the library provider, we do not know the full name of the scoped slot until runtime (when the user provides a list of fields for the table data). We then lookup in the |
I see. But what would |
It was just an example for using brackets in slot names. We were also thinking of, in the future, a way to target specific rows/columns (cells) based on the |
As long as the slot name starts with a letter or number you should be fine. |
It is too bad the new slot/scope syntax wasn't split into two "directives": <!-- pass a string literal as the slot name -->
<template v-slot="'slotName'" v-scope="{ some, props, here }"></template>
<!-- pass a variable containing the slot name -->
<template v-slot="someVar" v-scope="{ some, props, here }"></template> As this would retain case sensitivity on slot names (when using browser templates), allow spaces in slot names, and get around the restrictions that attribute names have (case insensitivity, special chars, and spaces) Within render functions, one can always use |
@posva see my comment at vuejs/rfcs#2 (comment) regarding the limitations of the new |
I saw it but nothing really changes... Things were already brought up. The problem you are highlighting is using weird names for slots which I would avoid in general and can be solved with render functions (in the library) which totally fits an advanced use case or using other characters as I said above so that end users are not limited. To recap:
Also, having 2 attributes instead of one to accommodate a very specific and non-readable use case doesn't seem to be worth to me |
@posva, I don't think you understand the situation I am referring to. Render functions don't fix the issues for users of the 3rd party library (it only fixes it for the 3rd party library portion). A user of the 3rd party library using SFC templates will run into the issue, and users of x-templates will also run into issues (specifically with case sensitive names being lost in browser). Example... user is using The table will render fine (as we use render functions to generate the table). But users can provide scoped slots to provide custom formatting for each field key in the table data (i.e. a column). the scoped slot name is based on the row's object property names (keys). So the scoped slot names (which are dynamic based on the fields present in the data) are in the format of It is more common situation than you are thinking it is, specifically when users have no control over the data being sent to them. The docs should be more clear on the limitations for in-browser users. The slot documentation section has no mention of the upper/lowercase issues. I'm not sure what you are referring to by "non-readable use case" An example of this use case can be found at: |
Not true. you can only use strings without spaces, and ones that do not have special characters used by directive attributes: i.e. This now requires consumers to have to re-map their data arrays and loose their original data structure |
I totally agree for the docs, the limitations should be mentioned but keep in mind this is an advanced and very specific use case that do not affect users in general and only affects a few library authors. We will be very happy if you want to lead the discussion there with other people facing the same issue and see how to improve the docs.
Talking about loader vs no-loader: spaces cannot work on html either as it's on the attribute side. The rest I already answered... |
Not entirely true. true for attribute names, not not true for attribute values. You can use strings with spaces as an attribute value:
And many, many, more consumers of those libraries (you are forgetting about the consumers, which is really the people affected by the issue). It is not just BootstrapVue users, but includes consumers of libs like Vuetify (they are now also affected by this issue, and will be SOL when Vue 3.x rolls out) when it comes to slots names that are not known until rum-time. |
v-slot
syntax does not support slot names that start with a square bracket [
v-slot
syntax does not support slot names that start with a square bracket [
or have spaces
v-slot
syntax does not support slot names that start with a square bracket [
or have spacesv-slot
syntax does not support slot names that start with a square bracket [
or names with spaces
I did think about end users. As I said I don't think a slot should be named
Those are usually stored in variables and used through |
That is why I prefer passing slot names as an attribute value instead of the attribute name (inside the double quotes, as with the old slot="name" syntax). the only restriction in attribute values is strings containing |
I'd like to add another situation that is impossible with the new slot syntax: A component that you can pass any number of slots to and uses the names in content. We have a component like this for tabs:
This was an intuitive way of dynamically passing any number of slots to a component without any unnecessary additional props (like making up an ID to be the slot name), and without needing an additional component. |
What problem does this feature solve?
We use slot names that use a bracketed syntax (specifically for dynamic slot names) i.e.
slot="[foo][bar]"
).v-slot:
currently supports slots names with square brackets, as long as they are not the first character of the slot name. i.e.v-slot:foo[bar]="scope"
(works), but notv-slot:[foo][bar]="scope"
(does not work)HTML5 allows for custom attributes with square brackets in the attribute name, as long as they do not start with restricted characters. However, in the case of
v-slot
, the attribute starts withv
, so slot names that start with[
should work as expected (i.e.v-slot:[foo.bar]
orv-slot:[foo][bar]
)Using the deprecated
slot="[foo]"
syntax works as expected.What does the proposed API look like?
v-slot
adds support for slot names that start with a[
, such asv-slot:[foo][bar]="scope"
There is no actual change to the API from the user perspective, just a change to the underlying code.
My guess that this is an issue with Vue template compiler:
From the template compiler on the Vuejs.org site (https://vuejs.org/v2/guide/render-function.html#Template-Compilation):
Does not work:
Does Work:
The text was updated successfully, but these errors were encountered: