From 68784363dca98529286420206b22a9a8881c70dc Mon Sep 17 00:00:00 2001 From: Jonni Nakari Date: Wed, 30 Mar 2016 23:22:14 +0300 Subject: Suggestion pop-up width API for ComboBox (#19685) Added API setPopupWidth(String) to ComboBox. The suggestion pop-up now has three different width modes: 1. Legacy "null"-mode: width is determined by the longest item caption for each page. This looks & feels like the old implementation. This is the default mode 2. Relative to the ComboBox. e.g. 100% 3. fixed width using any CSS definition Change-Id: Id60a6996ee82726196b84d50c2d0d18a6cfb5ebf --- server/src/main/java/com/vaadin/ui/ComboBox.java | 33 +++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'server') diff --git a/server/src/main/java/com/vaadin/ui/ComboBox.java b/server/src/main/java/com/vaadin/ui/ComboBox.java index b632cb0d8d..562173a9bf 100644 --- a/server/src/main/java/com/vaadin/ui/ComboBox.java +++ b/server/src/main/java/com/vaadin/ui/ComboBox.java @@ -121,6 +121,8 @@ public class ComboBox extends AbstractSelect implements */ private boolean scrollToSelectedItem = true; + private String suggestionPopupWidth = null; + /** * If text input is not allowed, the ComboBox behaves like a pretty * NativeSelect - the user can not enter any text and clicking the text @@ -170,7 +172,7 @@ public class ComboBox extends AbstractSelect implements /** * Sets the input prompt - a textual prompt that is displayed when the * select would otherwise be empty, to prompt the user for input. - * + * * @param inputPrompt * the desired input prompt, or null to disable */ @@ -230,6 +232,11 @@ public class ComboBox extends AbstractSelect implements target.addAttribute("pagelength", pageLength); + if (suggestionPopupWidth != null) { + target.addAttribute("suggestionPopupWidth", + suggestionPopupWidth); + } + target.addAttribute("filteringmode", getFilteringMode().toString()); // Paints the options and create array of selected id keys @@ -874,6 +881,16 @@ public class ComboBox extends AbstractSelect implements return pageLength; } + /** + * Returns the suggestion pop-up's width as a CSS string. + * + * @see #setPopupWidth + * @since 7.7 + */ + public String getPopupWidth() { + return suggestionPopupWidth; + } + /** * Sets the page length for the suggestion popup. Setting the page length to * 0 will disable suggestion popup paging (all items visible). @@ -886,6 +903,20 @@ public class ComboBox extends AbstractSelect implements markAsDirty(); } + /** + * Sets the suggestion pop-up's width as a CSS string. By using relative + * units (e.g. "50%") it's possible to set the popup's width relative to the + * ComboBox itself. + * + * @see #getPopupWidth() + * @since 7.7 + * @param width the width + */ + public void setPopupWidth(String width) { + suggestionPopupWidth = width; + markAsDirty(); + } + /** * Sets whether to scroll the selected item visible (directly open the page * on which it is) when opening the combo box popup or not. Only applies to -- cgit v1.2.3