Skip to content

Commit 8722afe

Browse files
committed
Added auto-close property on DatePicker
1 parent 021a410 commit 8722afe

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

gwt-material/src/main/java/gwt/material/design/client/ui/MaterialDatePicker.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ public enum MaterialDatePickerType {
9292
private MaterialDatePickerType selectionType = MaterialDatePickerType.DAY;
9393

9494
private boolean initialized = false;
95+
private boolean autoClose = false;
96+
private HandlerRegistration autoCloseHandler;
9597
private MaterialIcon icon = new MaterialIcon();
9698

9799
private ErrorMixin<AbstractValueWidget, MaterialLabel> errorMixin = new ErrorMixin<>(this, lblError, dateInput, lblPlaceholder);
@@ -138,6 +140,10 @@ public void onUnload() {
138140
super.onUnload();
139141

140142
dateTemp = getValue();
143+
144+
if (autoCloseHandler != null) {
145+
autoCloseHandler.removeHandler();
146+
}
141147
}
142148

143149
protected void initialize() {
@@ -181,8 +187,15 @@ protected void initialize() {
181187
}
182188

183189
$(pickatizedDateInput).pickadate("picker")
184-
.off(options)
185-
.on(options);
190+
.off(options)
191+
.on(options);
192+
193+
// Provide a feature to autoClose the picker when picking value
194+
if (isAutoClose()) {
195+
autoCloseHandler = addValueChangeHandler(valueChangeEvent -> {
196+
close();
197+
});
198+
}
186199

187200
initialized = true;
188201

@@ -567,4 +580,12 @@ public boolean isToggleReadOnly() {
567580
public DateInput getDateInput() {
568581
return dateInput;
569582
}
570-
}
583+
584+
public boolean isAutoClose() {
585+
return autoClose;
586+
}
587+
588+
public void setAutoClose(boolean autoClose) {
589+
this.autoClose = autoClose;
590+
}
591+
}

0 commit comments

Comments
 (0)