Replies: 3 comments 9 replies
-
These options are not deprecated and, I clarified that fact in the original issue already. Now, to your questions:
Yes.
Yes, you can. Or use
For a component using fragments,
Since the APIs are still there and available, I don't see anything major libraries would have to solve here. |
Beta Was this translation helpful? Give feedback.
-
@LinusBorg Ok thx for explanation sorry for all the bs probably should improve docs relating to $refs with composition apis, it is not clear that template refs are actually registered both under $refs and inside your declared setup variable (any caveats for having double references there?) also, placeholder element for fragments is not written anywhere in the docs (no mention of nextSibling, or how to use it) But this still raises a few questions like in the previous scenario <q-card ref="myCard"></q-card> If I don't know anything about the inside of the component, and want a generic solution for checking scrollTop for e.g.
what do you think? |
Beta Was this translation helpful? Give feedback.
-
@LinusBorg Heres another example of where it's needed and there are definitely many more. This should be solved somehow <q-input ref="myInput" v-model="value" dir="auto" />
...
setup() {
...
watch(value, () => {
isRTL.value = window.getComputedStyle(myInput.value.$el, null).direction === 'rtl';
})
...
} in following situation, if q-input uses fragments, this assertion would silently fail |
Beta Was this translation helpful? Give feedback.
-
Taken from here, to create a discussion vuejs/core#3868
What problem does this feature solve?
I have posted the following message in Quasar framework discussion board and thought of bringing it here for discussion as well as this is relevant for any Vue 3 application and especially relevant for ui frameworks
Since template refs are now declarative only, there is no standard way of accessing at the minimum, root elements.
My Post from quasarframework/quasar#9500:
Point for thought, now that this.$el and this.$refs are deprecated or removed from Vue 3, accessing the DOM get's much harder
Take for example very simple situations where you'd want to access the DOM of QPage to attach events programmatically, or maybe you want to focus on QBtn after an action or want to set the caret inside a QInput as discussed and solved specifically here
In Vue 2, this was a relatively easy task,
If I wanted to measure the width and height of QCard I could easily do this.$refs.myCard.$el.clientHeight or even the riskier this.$refs.myQInput.$refs.input to access native input element
There are many reasons we'd need access to the DOM and I certainly don't expect QBtn to implement focus() method or any other specific solutions
This is a problem with whole Vue 3 IMO and not specific to Quasar, but might be preemptively solved or discussed here
So my general direction for solution for this was having all or most components expose getRootElement() method systematically and others should also have getNativeElement() if relevant. This could relatively easily be implemented with shared composables, but the template ref part would still need to be implemented in all components individually
The only oversight I currently think of for this, and the reason this.$el was removed from Vue 3, is that components can now have more then 1 root element. Not sure of best way to solve this systematically but simplest solution would be to simply return an array of refs for getRootElement(). Maybe it should always return array for consistency
I would love to hear thoughts on this as I mulled over it for some time. I truly think this might have been an oversight on the Vue's team front
What does the proposed API look like?
So my general direction for solution for this was having all or most components expose getRootElement() method systematically and others should also have getNativeElement() if relevant. This could relatively easily be implemented with shared composables, but the template ref part would still need to be implemented in all components individually
The only oversight I currently think of for this, and the reason this.$el was removed from Vue 3, is that components can now have more then 1 root element. Not sure of best way to solve this systematically but simplest solution would be to simply return an array of refs for getRootElement(). Maybe it should always return array for consistency
In Vue 3 built with composition api only, would $el still be relevant? Are declared refs in composition api go to $refs object?
i.e.
If someone were to access the following component using a template ref, would myCard be registered with $refs?
would you access
myCard.value.$refs.cardContainer
if card used a composition template ref to register its container (which of course is dangerous by itself but sometimes unavoidable)?If it's using fragments and you want to calculate width and height or set scroll position, would you do
myCard.value.$el.scrollTop
?since it's from a third party library, you can't rely on card insides (options or composition).
Would each library have to solve this periodically for it self creating many different standards?
@LinusBorg Moved this over here
Beta Was this translation helpful? Give feedback.
All reactions