vaadin / platform

Vaadin platform 10+ is a Java web development platform based on Vaadin web components. If you don't know to which repository your bug report should be filed, use this and we'll move it to the right one.
https://vaadin.com
515 stars 76 forks source link

Labels-aside support in input field components #2631

Open rolfsmeds opened 2 years ago

rolfsmeds commented 2 years ago

Description

Built-in support for rendering labels "aside" (instead of on top) in all input field components, without the need for vaadin-form-item wrappers.

Acceptance criteria

General criteria

rolfsmeds commented 1 year ago

Open question: Should the API for this be a theme variant applied with something like theme="label-aside" / *Variant.LUMO_LABEL_ASIDE rather than a component feature with its own property?

rolfsmeds commented 1 year ago

One unfortunate detail in using the built-in label aside is that there's currently no way (that I'm aware of) to make the labels have dynamic width, i.e. automatically be as wide as the widest label in the form (e.g. in a vaadin-form-layout). Instead, a css property would be used to set a fixed width for the labels.

Dynamic label width is a feature of the css-grid form-layout refac here: https://github.com/vaadin/web-components/issues/4583, which still uses the current vaadin-form-item wrappers for having labels outside the component. So by using these aside-labels-in-components we lose that.

I'm quite certain dynamic label width would be possible with CSS sub-grid, but browser support is still quite far away: https://caniuse.com/css-subgrid

knoobie commented 1 year ago

Theme variant sounds fine! (If it's feasible to implement. Otherwise the property would be also okay)

knoobie commented 1 year ago

One unfortunate detail

Personally, I'm totally fine with that. Normally people should test their app with the supported locales anyway.

Dynamic label width

Couldn't this be implemented in the form? Like it knows all fields you add and calculates with JS the widest label and apply this width to the label? There are probably edge cases I forgot.. but it sounds possible theoretically.

rolfsmeds commented 1 year ago

Regardless of different strings for different locales, it would be useful to have dynamic label width, so that you wouldn't have to adjust the width in your forms at all – it would just automatically be wide enough for the labels, so that if you only have very short labels, the label "column" would only be as wide as they need, and if you have longer labels in another form, they'd automatically adapt to accommodate that.

But yes, you're correct in that it could probably be implemented with scripting. It's just that 1) that's a hassle, 2) those solutions tend to be buggy and/or not entirely reliable, and 3) pure css solution would be nicer.

knoobie commented 1 year ago

Sadly all three points are valid concerns πŸ™‡β€β™‚οΈ