vaadin / web-components

A set of high-quality standards based web components for enterprise web applications. Part of Vaadin 20+
https://vaadin.com/docs/latest/components
447 stars 83 forks source link

Text Area: clear / suffix / prefix buttons scroll out of view #7673

Open paodb opened 1 month ago

paodb commented 1 month ago

Description

If the Text Area has a fixed height and contains a clear button or other suffix/prefix, these buttons can be scrolled out of view when entering a multiline content.

Expected outcome

Clear button or other suffix/prefix should stay visible.

Minimal reproducible example

return html`
      <style>
        vaadin-text-area {
          width: 100%;
          height: 150px;
        }
      </style>

      <vaadin-text-area label="Description" clear-button-visible >
        <vaadin-icon slot="prefix" icon="vaadin:vaadin-h"></vaadin-icon>
      </vaadin-text-area>
    `;

Steps to reproduce

  1. Add the snipped above to a page
  2. Start entering text with several lines until vertical scroll appears
  3. See clear button and sufix icon getting no longer visible while keep entering lines

Environment

Vaadin version(s): 24.4.8

Browsers

No response

yuriy-fix commented 1 month ago

This issue has been added to the backlog priority queue for further investigation.

sissbruecker commented 2 weeks ago

@paodb We looked into possible solutions, but unfortunately fixing this will likely require a breaking change. So fixing this will take longer, at least until the next minor, or possibly the next major. There is a related issue for allowing users to resize the text area, which would also require a breaking change, so we might want to tackle those together at some point.

As an alternative I can provide two simple workarounds using CSS:

1 - Make the internal textarea scrollable

This changes the internal text area to be scrollable. Note that this moves the scroll bar to the left of the clear button or any suffix component.

vaadin-text-area textarea {
  max-height: 100%;
  overflow: auto;
}

Bildschirmfoto 2024-09-02 um 10 21 28

2 - Use position: sticky on prefix and suffix components

This prevents prefix and suffix components scrolling out of the viewport. Note that this also moves the clear button to the top, otherwise the clear button would still scroll until it reaches the top and then stop scrolling there.

vaadin-text-area [slot="prefix"],
vaadin-text-area [slot="suffix"],
vaadin-text-area::part(clear-button) {
  align-self: flex-start;
  position: sticky;
  top: 0;
}

Bildschirmfoto 2024-09-02 um 10 24 16

rolfsmeds commented 4 days ago

Hmm, are there any other drawbacks to workaround #2 above than that the clear button is always rendered at the top instead of in the vertical center? Because if not, I'm starting to feel like that might be not only a very innocuous breaking change but possibly actually preferable, especially if prefix/suffix elements are also used. If that's the only drawback, I would be in favor of just shipping that change as-is in the next minor.