Reputation: 785
A read-only TextField has a dashed border in Vaadin 14, like this one:
I want to remove the dashed border. For some TextFields (ideally only those with a special CSS classname - but I guess that the extension of the CSS selector is no problem later).
Therefore I created a file textfieldstyles.css in [projekt]/frontend/styles/ with this content:
[part="input-field"]::after {
border-style: none;
border-width: 0px;
border-color: white;
/* does not change anything: border: 0px none white; */
}
and added an annotation at my Vaadin-Java-component:
@CssImport(value = "./styles/textfieldstyles.css", themeFor = "vaadin-text-field")
This does not (fully) work as expected: my CSS code is part of the element's style (yeah, success :) ), but only AFTER the dashing style (oh no :( ). The result is still a dashed border. Here is a screenshot of Firefox inspector:
How can I rank my styles higher than the standard Vaadin styles?
Upvotes: 2
Views: 2037
Reputation: 587
I am trying to doing something similar and found this "official" way. You can add the following CSS in the index.html, which will change the border to a thin grey one instead of removing the dashed.
<dom-module id="read-only-field-styles" theme-for="vaadin-text-field">
<template>
<style>
:host(.read-only) [part="input-field"]::after {
border-style: solid;
border-width: thin;
border-color: grey;
}
</style>
</template>
</dom-module>
Then, add the class name "read-only" to all your vaadin-text-field
.
<vaadin-text-field class="read-only" label="XXX" id="xxx" readonly></vaadin-text-field>
Upvotes: 2
Reputation: 785
The problem (and the solution) was already in my question: "[...] I guess that the extension of the CSS selector is no problem later [...]".
Everything works fine when I use a more specialized CSS selector in [project]/frontend/styles/textfieldstyles.css:
:host(.my-special-classname) [part="input-field"]::after {
border-style: none;
border-width: 0px;
border-color: white;
}
The TextField of course has to get that class name:
textField.addClassName("my-special-classname");
Then Firefox shows the order I wanted to have and the Vaadin 14 readonly TextField has no dashed border any more:
Upvotes: 0
Reputation: 523
There are a few ways to accomplish what you want; most involve !important
, like:
border-color: transparent !important;
It's easy to abuse !important
to brute-force styles you want, but in this case, seems like an appropriate use. Btw you could also override other border-*
CSS attributes, but just one will do it, as in my example above. Also, avoiding changing border-width
means not changing layout at all; the button retains its dimensions (including border width) by just making the border invisible (transparent
).
Hope this helps!
Upvotes: 2