Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't style TextArea border in readonly mode #6503

Closed
SlimeAttack07 opened this issue Aug 6, 2024 · 2 comments · Fixed by vaadin/web-components#7624
Closed

Can't style TextArea border in readonly mode #6503

SlimeAttack07 opened this issue Aug 6, 2024 · 2 comments · Fixed by vaadin/web-components#7624

Comments

@SlimeAttack07
Copy link

Description of the bug

If I try to style a TextArea's border in readonly mode, I can't get the changes to show up. I presume this is because TextArea's readonly border styling happens in the shadow DOM:
Screenshot 2024-08-06 164750

The documentation (https://vaadin.com/docs/latest/components/text-area/styling) has a few possible selectors that don't work:

  • --vaadin-input-field-readonly-border property is shared by all input fields except TextArea.
  • vaadin-text-area[readonly] selector selects the regular css, but the border is applied in shadow DOM and hence this selector doesn't affect the border. In fact, setting a solid border here displays around the dashed readonly border, showing they're not selecting the same element.

Expected behavior

The border shouldn't be hardcoded in TextArea's shadow DOM. Instead, it should use the --vaadin-input-field-readonly-border property for that just like the other input fields do. In fact, manually setting the border to that in a browser's inspector and then setting the property to 'none' properly makes the border disappear.
Screenshot 2024-08-06 165313

Minimal reproducible example

  1. Make a TextField and set it to readonly mode ( myTextField.setReadOnly(true); ).
  2. Make a TextArea and set it to readonly mode ( myTextArea.setReadOnly(true); ).
  3. In your css's html tag, set --vaadin-input-field-readonly-border to none:
    html {
    --vaadin-input-field-readonly-border: none;
    }
  4. Observe that while the TextField's readonly border has vanished, the TextArea's readonly border remains.

Versions

  • Vaadin / Flow version: 24.3.12
  • Java version: 21
  • OS version: Windows 11
@mcollovati mcollovati transferred this issue from vaadin/flow Aug 6, 2024
@rolfsmeds
Copy link
Contributor

Good catch, apparently we forgot to refactor TextArea to use the --vaadin-input-field-readonly-border when it was introduced, so that needs to be fixed.

In the meantime, however, it is not a problem that the border is defined in shadow DOM css, as there is a part name selectors that allows you to target the appropriate element:

vaadin-text-area[readonly]::part(input-field) {
  border: 1px solid black;
}

@SlimeAttack07
Copy link
Author

Thanks! I'd tried out a few of the selectors from the documentation that didn't do what I needed. I didn't think about vaadin-text-area[readonly]::part(input-field) so I hadn't tried that yet.
Just tried it out and that does indeed do what I need, so I'll use that for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants