简体   繁体   English

悬停DIV时文本框失去焦点

[英]Text box loses focus when DIV is hovered

I have a problem: When I enter a text into suggestion text box, popup panel appears. 我有一个问题:当我在建议文本框中输入文本时,会出现弹出面板。 But when user places mouse over this popup panel with suggestions - text box loses focus. 但是,当用户将鼠标悬停在带有建议的弹出面板上时,文本框将失去焦点。

What should I do to prevent losing focus ? 我应该怎么做才能避免失去焦点?

Example which have the same behaviour: http://demo.raibledesigns.com/gwt-autocomplete/ 具有相同行为的示例: http : //demo.raibledesigns.com/gwt-autocomplete/

Thanks for any help. 谢谢你的帮助。

Update 1 更新1

SuggestionMenu which is being shown is extending MenuBar which sets focus for all menu items. 正在显示的SuggestionMenu扩展了MenuBar ,它设置了所有菜单项的焦点。

void itemOver(MenuItem item, boolean focus) {
    if (item == null) {
      // Don't clear selection if the currently selected item's menu is showing.
      if ((selectedItem != null)
          && (shownChildMenu == selectedItem.getSubMenu())) {
        return;
      }
    }

    // Style the item selected when the mouse enters.
    selectItem(item);
    if (focus) {
      focus();
    }

    // If child menus are being shown, or this menu is itself
    // a child menu, automatically show an item's child menu
    // when the mouse enters.
    if (item != null) {
      if ((shownChildMenu != null) || (parentMenu != null) || autoOpen) {
        doItemAction(item, false);
      }
    }
  }

It's clear that i cant fix loosing focus. 很明显,我无法解决失去的焦点。 Now question is - how to make on pressing backspace or any key to focus on edit box? 现在的问题是-如何使按下退格键或任何键集中在编辑框上?

Thanks in advance 提前致谢

I guess this is your code? 我想这是您的代码? Or is this a snippet from gwt source? 还是这是来自gwt的片段?

My guess is that this is your custom code... In that case you shouldn't focus the element to style it but instead attach a handler... sth like 我的猜测是这是您的自定义代码...在这种情况下,您不应该将元素放在样式上,而应该附加一个处理程序...

public HandlerRegistration addMouseOutHandler(MouseOutHandler handler) {
  return this.addDomHandler(handler, MouseOutEvent.getType());
}
public HandlerRegistration addMouseOverHandler(MouseOverHandler handler) {
  return this.addDomHandler(handler, MouseOverEvent.getType());
}


element.addMouseOutHandler(new MouseOutHandler() {
  public void onMouseOut(MouseOutEvent event) {
    element.removeStyleName(HEADER_STYLE_HOVERING);
  }
});

element.addMouseOverHandler(new MouseOverHandler() {
  public void onMouseOver(MouseOverEvent event) {
    element.addStyleName(HEADER_STYLE_HOVERING);
  }

});

just replace the element with whatever you want to attach the handlers to. 只需将元素替换为要附加处理程序的元素即可。

Does this help you? 这对你有帮助吗?

I found the problem. 我发现了问题。 I have used GWT 1.7.0. 我使用了GWT 1.7.0。 - and it's has focus() call in it's source code. -它的源代码中包含focus()调用。

This problem can be solved by updating to GWT v2. 通过更新到GWT v2可以解决此问题。

Thanks markovuksanovic for help! 感谢markovuksanovic的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM