fix(Dropdown): when disabled chip has extra class #2650
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
https://monday.monday.com/boards/3532714909/pulses/8041715569
Explanation about the solution:
We had a few issues.
The
isCounterShown
dependency in theuseHiddenOptionsData
caused infinite loop, as twouseEffect
s were called infinitely.It is in the dependency array as the Dropdown calculates what chips should be hidden.
But when calculated, the counter of "+X" chip at the end isn't shown (yet), so in some scenarios you could have pushed another chip to the width of the Dropdown (let's say 4 out of 5), but then when the counter appeared (to show "+1") as it should, the whole logic got messed up (cause chip number 4 did not had space anymore as the "+1" counter, which should now show "+2", caused it to be pushed out of boundaries), and we got caught up in an infinite loop.
I solved it, a temporary solution, by fixing the disabled state classes (which was buggy anyway - we probably never calculated the counter correctly for disabled state (!!)). It helped with solving the infinite loop, but there might be very specific and very edgy scenarios where the infinite loop would happen again because of the counter dependency.
On the new Dropdown design we should take this kind of stuff into consideration and build it better future-proof @rivka-ungar.
P.S. neither Claude or GPT correctly understood what's going on there, which means this logic is really messed up 🙃.
code that fails on previous version:
Try it in the Playground.
while changing the width to 435px shows everything correct, having 434px fails.
in compare to this PR, where the Playground with the changes from the PR shows everything correct.