Reputation: 554
How can I change the style of a readonly TextField in Vaadin?
Now the default style after setting setReadOnly(true) is following:
I want this style with no border and an other backgroundcolor:
How can I achieve this?
Upvotes: 2
Views: 263
Reputation: 36
I had the same problem and I corrected it by adding the next CSS selector to my styles.css
(or any CSS file that your project loads)
.custom-textfield[readonly]::part(input-field) {
--vaadin-input-field-readonly-border: none;
}
What I'm doing is setting a custom value to the property --vaadin-input-field-readonly-border
that removes border.
Note that, I'm applying it to elements with the class name custom-textfield
. If you want this behavior to all your TextFields, you can reassign the property's value in the .html selector of your styles.css file.
html, :host {
--vaadin-input-field-readonly-border: none;
}
On this page, you can check all style properties for TextFields: Styling | Text Field
Upvotes: 2
Reputation: 708
you could try with this code for that particular text field you want to modify:
TextField textField = new TextField();
textField.setReadOnly(true);
// Remove border and set background color to gray
textField.getElement().getStyle().set("border", "none");
textField.getElement().getStyle().set("background-color", "gray");
it is worth noticing that if you want the whole application with that style please follow the documentation.
in there you can find how to customize all the text fields in your application.
Upvotes: 0