Skip to content

Commit f6959a4

Browse files
committed
Add ComboBox to enable focus support.
1 parent 0ec1400 commit f6959a4

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class MaterialComboBox<T> extends AbstractValueWidget<List<T>> implements
118118
private int selectedIndex;
119119
private boolean open;
120120
private boolean suppressChangeEvent;
121+
private boolean enableFocus;
121122
protected List<T> values = new ArrayList<>();
122123
private Label label = new Label();
123124
private MaterialLabel errorLabel = new MaterialLabel();
@@ -224,12 +225,14 @@ public void load() {
224225
return true;
225226
});
226227

227-
body().on(ComboBoxEvents.FOCUS, getSelectContainerSelector(), (e, param1) -> {
228-
if (!e.getCurrentTarget().getClassName().contains("select2-container--focus")) {
229-
DomEvent.fireNativeEvent(Document.get().createFocusEvent(), this, getElement());
230-
}
231-
return false;
232-
});
228+
if (enableFocus) {
229+
body().on(ComboBoxEvents.FOCUS, getSelectContainerSelector(), (e, param1) -> {
230+
if (!e.getCurrentTarget().getClassName().contains("select2-container--focus")) {
231+
DomEvent.fireNativeEvent(Document.get().createFocusEvent(), this, getElement());
232+
}
233+
return false;
234+
});
235+
}
233236

234237
body().on(ComboBoxEvents.KEYUP, getSearchFieldElement(), e -> {
235238
KeyEvent keyEvent = (KeyEvent) e;
@@ -1268,6 +1271,14 @@ public void setSearchInputValue(String value) {
12681271
$(getSearchFieldElement()).val(value);
12691272
}
12701273

1274+
public boolean isEnableFocus() {
1275+
return enableFocus;
1276+
}
1277+
1278+
public void setEnableFocus(boolean enableFocus) {
1279+
this.enableFocus = enableFocus;
1280+
}
1281+
12711282
@Override
12721283
public void setAsyncDisplayLoader(AsyncDisplayLoader displayLoader) {
12731284
getAsyncWidgetMixin().setAsyncDisplayLoader(displayLoader);

0 commit comments

Comments
 (0)