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
Allow customizing overlay width #529
Comments
We had a prototype about something like this for 1.x version not long ago. Now that I think back, one of the problems is that we are using iron-list, and that positions the items absolutely, so the width of the items do not affect the width of the overlay. So we would still have to measure the width of the items to be able to make the overlay adjust to it. @tomivirkki’s “flexbox” scroller could eventually fix this nicely ;) |
Coming back to this a bit – it doesn’t really help to expose a custom CSS property for the overlay. Because of the “teleporting”, you can’t really target the correct overlay in any way currently. We need something like vaadin/vaadin-overlay#48 to make it possible to target individual overlay elements. If we could propagate the class attribute (or some other attribute) to the overlay: <vaadin-combo-box class="my-combo-box"></vaadin-combo-box>
<dom-module id="my-combo-box-overlay" theme-for="vaadin-combo-box-overlay">
<template>
<style>
:host(.my-combo-box) [part="overlay"] {
width: 300px; /* Your custom width here */
}
</style>
</template>
</dom-module> An unfortunate amount of boilerplate, but I can’t think of any other way right now. |
It could also be a specific attribute that we propagate, like |
Why introducing a "width" setting and not just fit the (longest) item width? One might not know in advance the width to set. |
Because of the virtual scroller, we don’t know the width of all items. We could base it on the first page of items, though. In any case, it needs some JS to compute it, can’t be based on CSS alone, unfortunately. At least now that the |
Is there something like |
Working example: https://glitch.com/edit/#!/foul-macaroni?path=index.html:10:0 We can consider using CSS custom property, too. But as mentioned above, there would be anyway the need for |
Thanks a lot, works now! |
I strongly recommend adding a css variable for setting the overlay width, seeing as how that should be quite simple to add to the current implementation. This is an extremely common need in cases where the field only needs to show a short code but the list items need to display a human-friendly name as well, and making the entire combo extra special wide just for that is really akward. |
I suppose one possible workaround, that allows setting any arbitrary width to any combobox, without hardcoded predefined widths, would be to have a method that takes a width property as argument, e.g. Then you just need a single theme module that utilizes that custom property to override the overlay's width with But, uh, a built-in solution would certainly be nicer :) |
I've implemented the workaround, but this causes another problem: the popup is always left-aligned with the text field. This means if your combo is near the right-hand edge of the window, the popup is cropped. Modification of the original example to show the problem: https://glitch.com/~unmarred-titanium-vermicelli |
Related issue for Flow API https://github.com/vaadin/vaadin-combo-box-flow/issues/155 |
Expose a property like
--vaadin-combo-box-width
that can be used to configure the overlay width.Would be helpful especially in situations where the dropdown contents are wider than the actual input field.
The text was updated successfully, but these errors were encountered: