web-components icon indicating copy to clipboard operation
web-components copied to clipboard

Scale width of vaadin-select according to the selected item

Open danielvanmil opened this issue 3 years ago • 1 comments

Describe your motivation

Vaadin-select can be scaled with custom css properties:

  • --vaadin-field-default-width
  • --vaadin-select-text-field-width

Describe the solution you'd like

It would be nice when the select auto scales with width of the selected item when no static width is needed.

Describe alternatives you've considered

No response

Additional context

No response

danielvanmil avatar Sep 28 '22 11:09 danielvanmil

Could be considered for other fields as well.

yuriy-fix avatar Oct 04 '22 10:10 yuriy-fix

any updates on this?

danielvanmil avatar Feb 16 '23 10:02 danielvanmil

My prototype implementation for native input and select elements:

  • https://jelements.netlify.app/prototypes/input-decorator/#auto-size
  • https://github.com/jouni/j-elements/blob/master/src/components/InputDecorator.js#L103-L137

That said, it should be easier to implement this for <vaadin-select>, with just CSS.

jouni avatar Feb 17 '23 12:02 jouni

Here’s the CSS that should get the result (assuming Vaadin 23.3 or later):

vaadin-select {
  --vaadin-field-default-width: auto;
}

vaadin-select-value-button {
  width: auto;
  /* Relying on the internal custom property to remove the overflow mask image */
  --_lumo-text-field-overflow-mask-image: none; 
}

jouni avatar Feb 17 '23 12:02 jouni

thanks @jouni! Any chance this "feature" will be added to the default Vaadin or might even become standard behavior?

danielvanmil avatar Mar 02 '23 08:03 danielvanmil

I don't think we want to change the default behavior, not at least with v23 or v24. Could be considered for v25, but I wonder if it's worth the trouble. I would think a built-in variant (opt-in per instance) would be good enough.

jouni avatar Mar 02 '23 14:03 jouni