Skip to content
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

fix(Dropdown): when disabled chip has extra class #2650

Conversation

YossiSaadi
Copy link
Contributor

@YossiSaadi YossiSaadi commented Dec 12, 2024

https://monday.monday.com/boards/3532714909/pulses/8041715569

Explanation about the solution:
We had a few issues.
The isCounterShown dependency in the useHiddenOptionsData caused infinite loop, as two useEffects 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:

() => {
  const options = [
    {
      value: 1,
      label: 'Option 1',
    },
    {
      value: 2,
      label: 'Option 2',
    },
    {
      value: 3,
      label: 'Option 3',
    },
    {
      value: 4,
      label: 'Option 4',
    },
    {
      value: 5,
      label: 'Option 5',
    },
  ]

  const selected = [...options]; 

  return (
    <Flex direction="column" align="start" gap="medium">
      <div style={{ width: 434 }}>
        <Dropdown
          multi
          options={options}
          value={selected}
          disabled
        >
        </Dropdown>
      </did>
    </Flex>
  );
}

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.

@YossiSaadi YossiSaadi marked this pull request as ready for review December 13, 2024 08:01
@YossiSaadi YossiSaadi requested a review from a team as a code owner December 13, 2024 08:01
@YossiSaadi YossiSaadi merged commit 3bf35bd into master Dec 15, 2024
14 checks passed
@YossiSaadi YossiSaadi deleted the fix/yossi/dropdown-disabled-with-multi-chips-and-fixed-width-causes-8041715569 branch December 15, 2024 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants