Open chrschorn opened 6 months ago
Hi @chrschorn,
That's a great observation. When implementing and extending getElement
, we tried to (almost) always return something "useful", but we introduced an annoying inconsistency. We thought, from the user's perspective, it shouldn't matter if a NiceGUI element is based on a Vue component or a plain HTML element. But of course, if you want to do something with it, the difference matters. One could argue that, if you know that an element is based on Vue, you can step into the HTML element using $el
, as you did. But this isn't very intuitive, let alone documented.
To support explicit access to Vue components or HTML elements - without breaking the existing API -, we might want to introduce new functions like getHtmlElement
and getVueComponent
, and deprecate or at least discourage using getElement
.
But besides that, what can we do about ui.input
? Quasar takes the q-input
tag and replaces it with a whole tree of HTML with a <label>
as root, but without setting the "id" attribute. I'm not sure what we could do about it, but it would be great to get some kind of consistency with other UI elements.
Description
Hi, originally I wanted to implement a "scroll to element" functionality in an application I'm working on. You can use scrollIntoView() on the DOM node to achieve that. But: how can I get the DOM node for any NiceGUI element?
The issue I ran into:
element.run_method("scrollIntoView")
and it works. This seems to be the case when the NiceGUI element is just a simple dom node to begin with, e.g.ui.label
which is a div$el
to get the DOM node of the vue component.Here are some examples that work with
run_method
, then a customscroll_to
I wrote and thenui.input
which I couldn't get to work at all:Is there already an easy way to get the root DOM node of the NiceGUI element? According to https://nicegui.io/documentation/run_javascript, it should be
getElement
, but this either returns a DOM node, vue component where$el
refers to the root DOM node or, in cases likeui.input
, something where even$el
points to a non-DOM object.It would be good to have a reliable way to get the DOM node for an element. Maybe
run_method
could have a bool argumentdom_element
? Providing a javascript function documented onrun_javascript
could also work.