Skip to content

Fit Context Menu Height to Menu #805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions core/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Blockly.ContextMenu.currentBlock = null;
* @param {boolean} rtl True if RTL, false if LTR.
*/
Blockly.ContextMenu.show = function(e, options, rtl) {
var menuHeight = 0;
Blockly.WidgetDiv.show(Blockly.ContextMenu, rtl, null);
if (!options.length) {
Blockly.ContextMenu.hide();
Expand Down Expand Up @@ -104,8 +105,11 @@ Blockly.ContextMenu.show = function(e, options, rtl) {
x -= menuSize.width;
}
}
Blockly.WidgetDiv.position(x, y, windowSize, scrollOffset, rtl);

menu.children_.forEach(function(element) {
menuHeight += element.element_.clientHeight;
});
Blockly.WidgetDiv.position(x, y, {height: menuHeight, width: windowSize}, scrollOffset, rtl);

menu.setAllowAutoFocus(true);
// 1ms delay is required for focusing on context menus because some other
// mouse event is still waiting in the queue and clears focus.
Expand Down