如何使用 max-height 和 Overflow-y: 滚动自动滚动 GWT SuggestBox?
如何在持有 SuggestBox
的 PopupPanel
上设置最大高度来自动滚动 GWT SuggestBox
?目前,当用户按键盘向上键和向下键时,建议项目的样式会发生变化,并且按 Enter 键将选择列表中当前选定的项目。
当项目位于低于最大高度时,滚动条不会滚动。 我尝试扩展 SuggestBox
和内部类 DefaultSuggestionDisplay
来覆盖 moveSelectionDown()
和 moveSelectionUp()
以显式调用 <代码>popup.setScrollTop()。
为了做到这一点,我需要访问当前选定的 MenuItem
的绝对顶部,因此需要访问 SuggestionMenu
它也是 SuggestBox 的内部类,它是私有的并声明为DefaultSuggestionDisplay
中的私有成员,不带 getter。由于 GWT 是 JavaScript,我们无法使用反射来访问它......有人有解决此问题的方法吗?
谢谢。
How can I auto scroll the GWT SuggestBox
with max-height set on the PopupPanel
holding the SuggestBox
? Currently when the user presses keyboard up keys and down keys styles changes on the suggested items and pressing enter will select the currently selected item on the list.
When the item is located in lower than the max-height scroll bars doesn't scroll.
I tried extending the SuggestBox
and inner class DefaultSuggestionDisplay
to override moveSelectionDown()
and moveSelectionUp()
to explicitly call popup.setScrollTop()
.
In order to do this I need access to the absolute top of the currently selected MenuItem
therefore need access to SuggestionMenu
which is also an inner class of SuggestBox which is private and declared as a private member within DefaultSuggestionDisplay
without getter. Since GWT is a JavaScript we can't use reflection to access it.... Does anyone have a workaround for this issue?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我一直在四处寻找,但找不到合适的解决方案(除了重新实现 SuggestBox 之外)。以下内容避免重新实现 SuggestBox:
}
I've been searching around and couldn't find a proper solution (apart from reimplementing SuggestBox). The following avoids reimplementing SuggestBox:
}
根据 Google 网上论坛的此讨论,我实现了类似的解决方案由于使用了 JSNI 而更加简洁:
Following this discussion on Google groups, I implemented a similar solution which is a bit more concise due to the use of JSNI:
好吧,我终于找到了解决方案。我必须基于 GWT SuggestBox 实现创建自己的建议框。但在自定义实现中请遵循以下步骤:
-将 ScrollPanel 放置到 PopupPanel,然后将 MenuBar 放置到 ScrollPanel
- 在新的内部 SuggestionDisplat 实现的 moveSelectionUp() 和 moveSelectionDown() 中添加以下代码:
这无法通过扩展 SuggestBox 来实现,因为我们无法访问选定的内容
MenuItem 除非重写受保护的 getSelectionItem() 方法作为公共方法。
最后添加 CSS:
到显示实现中的 popupPanel 中。
Ok, I finally found the solution. I had to create my own suggest box based on GWT SuggestBox implementations. But follow below in custom implementaion:
-Place ScrollPanel to PopupPanel then place MenuBar to ScrollPanel
-In moveSelectionUp() and moveSelectionDown() of your new internal SuggestionDisplat implementation add the code below:
This is not achievable by extending the SuggestBox since we won't have access to selected
MenuItem unless overriding protected getSelectionItem() method as public method.
Finally add CSS:
To the popupPanel in your display implementations.