Closed elmart closed 8 years ago
Thanks for the feedback! I won't be able to look into this before next week, but I'll be sure to get back to you with what I find. I don't remember the details of why not memoizing caused this behavior so there may be an alternate solution.
Hey @elmart, sorry for the delay. I'm having trouble getting a reliable test case together because of issues that seem to be related to:
select2:open
event to fire twice (https://github.com/select2/select2/pull/3507).I'm going to keep digging but in the meantime if you might be able to produce a jsFiddle or other code snippet that demonstrates the problem you're facing, that would help a lot with me making sure a fix actually works for your use case.
@elmart, would you be able to try the code in this commit (https://github.com/panorama-ed/maximize-select2-height/commit/fddb5a3fe3afce34c4ae6011da3c6cbaec9e0ef1) and see if that fixes your issue?
(You can just copy-paste the minified code here: https://raw.githubusercontent.com/panorama-ed/maximize-select2-height/fddb5a3fe3afce34c4ae6011da3c6cbaec9e0ef1/maximize-select2-height.min.js)
I think that should fix the issue for you as it removes the memoization that was at the heart of your problem, but I came across some bizarre edge cases, particularly with very small window sizes, that weren't well-supported by Select2's core and thus also behave badly with this plugin. I'm happy to go into more details if you like.
If it's helpful, the commit I linked to also includes the HTML file (with JS inlined) that I was using to play around with and test this behavior.
Hi guys. I'm very sorry I didn't respond before. I had my computer broken and it took some time to repair.
Proposed solution doesn't work in the dropdownDownwards case, but I had it working with a small fix (there was a mistaken sign). I'll comment the exact line in the PR. Apart from that, there's a little flickering which gets disturbing, but that's a different issue, and I'm afraid that would be more difficult/impossible to solve from outside select2.
So, once the appointed problem is solved, I consider this fixed.
Thx for your time.
Good catch, @elmart! I was so busy testing my changes for the upwards direction that I totally missed the bug I had introduced for the downwards direction. This is now fixed. Hope the new changes (and new computer) work well for you!
Plugin currently memoizes element's top offset the first time it needs it. In
topOffset()
:Now, I have a select2 within a floating modal window. There, it's not rare for the user to move the window between one select2:open event and the next one. That makes memoized top offset obsolete, and consequent optimal height calculation wrong.
I tried to remove enclosing if, to always calculate the value, but then, I have wrong behaviour when rendering upwards. The comment above mentions something about this, but I'm not sure about which the correct fix would be.
Any indication about how to proceed, please?