|
19 | 19 | */ |
20 | 20 | package gwt.material.design.addins.client.popupmenu; |
21 | 21 |
|
| 22 | +import com.google.gwt.core.client.Scheduler; |
22 | 23 | import com.google.gwt.dom.client.Element; |
23 | 24 | import com.google.gwt.event.logical.shared.*; |
24 | 25 | import com.google.gwt.event.shared.HandlerRegistration; |
@@ -56,6 +57,7 @@ public class MaterialPopupMenu extends UnorderedList implements JsLoader, HasSel |
56 | 57 | private String id; |
57 | 58 | private Object selected; |
58 | 59 | private boolean autoClose = true; |
| 60 | + private boolean autoFocus = false; |
59 | 61 |
|
60 | 62 | public MaterialPopupMenu() { |
61 | 63 | id = DOM.createUniqueId(); |
@@ -189,7 +191,7 @@ public HandlerRegistration addSelectionHandler(SelectionHandler<Element> selecti |
189 | 191 | @Override |
190 | 192 | public void open() { |
191 | 193 | setVisible(true); |
192 | | - /*Scheduler.get().scheduleDeferred(() -> setFocus(true));*/ |
| 194 | + if (autoFocus) Scheduler.get().scheduleDeferred(() -> setFocus(true)); |
193 | 195 |
|
194 | 196 | // Check if dropdown is out of the container (Left) |
195 | 197 | if ($(this).width() + $(this).offset().left > body().width()) { |
@@ -217,6 +219,14 @@ public void setSelected(Object selected) { |
217 | 219 | this.selected = selected; |
218 | 220 | } |
219 | 221 |
|
| 222 | + public boolean isAutoFocus() { |
| 223 | + return autoFocus; |
| 224 | + } |
| 225 | + |
| 226 | + public void setAutoFocus(boolean autoFocus) { |
| 227 | + this.autoFocus = autoFocus; |
| 228 | + } |
| 229 | + |
220 | 230 | @Override |
221 | 231 | public HandlerRegistration addCloseHandler(CloseHandler<MaterialPopupMenu> closeHandler) { |
222 | 232 | return addHandler(new CloseHandler<MaterialPopupMenu>() { |
|
0 commit comments