We don't support "visibility" feature for the text elements (its state provider throws unsupported operation exception).
But we have Text as a component. So I would expected that its setVisible method doesn't throw an exception on this API level.
It's not really obvious whether we need this feature for Text node at all.
But we need to do one of two options:
The latter item is easy on the server side (just make VisibilityData feature available for the text element).
But it's not easy on the client side.
At the moment we are hiding element on the client side using "hidden" attribute.
But it won't work for Text node.
May be in this case we should use a fake node to replace the node in the parent as suggested in my initial proposition here: https://github.com/vaadin/flow/issues/3146
Another potential approach could be to leave the text node in the DOM, but set the textContent property to "".
True.
But its value still should be preserved somewhere in case it becomes visible back.
The real text would still be stored the state node, but the contents of the DOM node would differ based on the VisibilityData setting for the same state node.
Yeah, of course. We already have this data in the StateNode.
Forgot about that.
That way is really better.
Currently an UnsupportedOperationException is thrown for using setVisible on a Text component. While it would take a day or so to fix this, let's see if someone will actually want to use the Text component and then make it invisible.
My use-case: when dumping the Vaadin component hierarchy as a pretty-print tree to a console when using serverless tests, I also try to print information about the Text node, whether it is visible or not. However, that crashes:
java.lang.UnsupportedOperationException
at com.vaadin.flow.dom.impl.AbstractTextElementStateProvider.isVisible(AbstractTextElementStateProvider.java:209)
at com.vaadin.flow.dom.Element.isVisible(Element.java:1435)
at com.vaadin.flow.component.Component.isVisible(Component.java:493)
at com.github.karibu.testing.PrettyPrintTreeKt.toPrettyString(PrettyPrintTree.kt:63)
Due to lack of requests for this, not considering this a worthy addition.
There is a way to workaround this by using e.g. new Div(new Text("")) and then setting that invisible.
Most helpful comment
Currently an
UnsupportedOperationExceptionis thrown for usingsetVisibleon aTextcomponent. While it would take a day or so to fix this, let's see if someone will actually want to use theTextcomponent and then make it invisible.