Skip to content

Commit febe408

Browse files
committed
Combobox - Added new property dropdownParent() to easily update where is the dropdown to be placed.
Added JUnit test to new property dropdownParent() on ComboBox.
1 parent acf5e53 commit febe408

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/main/java/gwt/material/design/addins/client/combobox/MaterialComboBox.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class MaterialComboBox<T> extends AbstractValueWidget<List<T>> implements
101101
private boolean hideSearch;
102102
private int limit;
103103
private boolean closeOnSelect = true;
104+
private String dropdownParent = "body";
104105
private boolean suppressChangeEvent;
105106

106107
private int selectedIndex;
@@ -150,6 +151,7 @@ protected void initialize() {
150151
options.placeholder = placeholder;
151152
options.maximumSelectionLength = limit;
152153
options.closeOnSelect = closeOnSelect;
154+
options.dropdownParent = $(dropdownParent);
153155

154156
if (clearInputHandler == null) {
155157
clearInputHandler = addSelectionHandler(valueChangeEvent -> $(getElement()).find("input").val(""));
@@ -227,6 +229,17 @@ public void add(Widget child) {
227229
listbox.add(child);
228230
}
229231

232+
/**
233+
* Sets the parent element of the dropdown
234+
*/
235+
public void setDropdownParent(String dropdownParent) {
236+
this.dropdownParent = dropdownParent;
237+
}
238+
239+
public String getDropdownParent() {
240+
return dropdownParent;
241+
}
242+
230243
/**
231244
* Sets multi-value select boxes.
232245
*/

src/main/java/gwt/material/design/addins/client/combobox/js/JsComboBoxOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
package gwt.material.design.addins.client.combobox.js;
2121

22+
import gwt.material.design.jquery.client.api.JQueryElement;
2223
import jsinterop.annotations.JsPackage;
2324
import jsinterop.annotations.JsProperty;
2425
import jsinterop.annotations.JsType;
@@ -34,6 +35,9 @@ public class JsComboBoxOptions {
3435
@JsProperty
3536
public String placeholder;
3637

38+
@JsProperty
39+
public JQueryElement dropdownParent;
40+
3741
@JsProperty
3842
public boolean allowClear;
3943

src/test/java/gwt/material/design/addins/client/MaterialComboBoxTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ protected <T extends MaterialComboBox<User>> void checkProperties(T comboBox) {
109109
assertEquals(comboBox.getLabel().getText(), "label");
110110
comboBox.setPlaceholder("placeholder");
111111
assertEquals(comboBox.getPlaceholder(), "placeholder");
112+
113+
final String BODY_SELECTOR = "body";
114+
final String SELF_SELECTOR = "#" + comboBox.getElement().getId();
115+
assertEquals(comboBox.getDropdownParent(), BODY_SELECTOR);
116+
comboBox.setDropdownParent(SELF_SELECTOR);
117+
assertEquals(comboBox.getDropdownParent(), SELF_SELECTOR);
112118
}
113119

114120
protected <T extends MaterialComboBox> void checkEvents(T comboBox) {

0 commit comments

Comments
 (0)