[Dropdown] module.is.onScreen returns wrong result when context is changed #5366
Closed
Description
Have a look at this fiddle. The menu opens above the dropdown and not below as expected.
The reason is that module.is.onScreen uses $currentMenu.offset() for it's calculations. Unfortunately the returned coordinates are relative to the document and not relative to the supplied context.
I think you need to calculate the offset relative to the supplied context, like this:
calculations = {
context: {
scrollTop : $context.scrollTop(),
offset : $context.offset(),
height : $context.outerHeight()
},
menu : {
offset: $currentMenu.offset(),
height: $currentMenu.outerHeight()
}
};
onScreen = {
above : (calculations.context.scrollTop) <= calculations.menu.offset.top - calculations.context.offset.top - calculations.menu.height,
below : (calculations.context.scrollTop + calculations.context.height) >= calculations.menu.offset.top - calculations.context.offset.top + calculations.menu.height
};