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

API for setting dropdown popup overlay width #2331

Closed
mvysny opened this issue Nov 12, 2021 · 4 comments · Fixed by #5743
Closed

API for setting dropdown popup overlay width #2331

mvysny opened this issue Nov 12, 2021 · 4 comments · Fixed by #5743
Labels
enhancement New feature or request vaadin-combo-box

Comments

@mvysny
Copy link
Member

mvysny commented Nov 12, 2021

Describe your motivation

In certain apps, certain ComboBoxes tend to have items with long texts. If the text won't fit the default dropdown popup width, the text will wrap, which is often not desired.

It would be good to have a means to override the dropdown width and specify an exact number in pixels.

This was filed as vaadin/vaadin-combo-box-flow#387 ; the issue was closed but not implemented since there's no Java API.

Describe the solution you'd like

I want to be able to call comboBox.setDropdownWidth("30em").

Additional context

Workaround/how this function should be implemented:

comboBox.getElement().getStyle().set("--vaadin-combo-box-overlay-width", width.trim())
@web-padawan web-padawan added the enhancement New feature or request label Nov 12, 2021
@archiecobbs
Copy link

This bug is basically a one line fix, and yet is over 1.5 years old.

What's the holdup??

@mvysny
Copy link
Member Author

mvysny commented Aug 23, 2023

Workaround for Kotlin: use karibu-tools

@mvysny
Copy link
Member Author

mvysny commented Nov 21, 2023

Solution for ComboBox and MultiSelectComboBox:

@Route("")
public class MainView extends VerticalLayout {

    public MainView() {
        final ComboBox<String> cb = new ComboBox<>("cb");
        cb.setItems("1", "2", "3");
        setDropdownWidth(cb, "40em");
        final MultiSelectComboBox<String> mcb = new MultiSelectComboBox<>("mcb");
        mcb.setItems("1", "2", "3");
        setDropdownWidth(mcb, "60em");
        add(cb, mcb);
    }

    private static void setDropdownWidth(ComboBox<?> cb, String width) {
        cb.getStyle().set("--vaadin-combo-box-overlay-width", width);
    }
    private static void setDropdownWidth(MultiSelectComboBox<?> cb, String width) {
        cb.getStyle().set("--vaadin-multi-select-combo-box-overlay-width", width);
    }
}

@mvysny
Copy link
Member Author

mvysny commented Nov 21, 2023

Acceptance criteria: set the width of the dropdown to 30em or larger, and observe that the dropdown is visibly wider than the ComboBox itself.

sissbruecker added a commit that referenced this issue Jan 15, 2024
…ayWidth() (#5743)

* feat: add ComboBox.setDropdownWidth() and MultiSelectComboBox.setDropdownWidth(). Fixes #2331

* refactoring: rename setDropdownWidth() to setOverlayWidth()

* refactoring: rename setDropdownWidth() to setOverlayWidth()

* align test names

---------

Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-combo-box
Projects
None yet
3 participants