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: <Select/> when !multiple || !box #1613

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bigmistqke
Copy link

@bigmistqke bigmistqke commented Aug 16, 2023

Why

When the props multiple and box are defined, downed is being set through eventListeners set on the window inside an effect. If they are not set, downed was initially never set, which caused onChange to never run.

An example of Select not working is the With <Select/>-story of TransformControls.

What

  • add a condition const shouldDragSelect = multiple && box
  • conditional event-listeners on <group/> in case !shouldDragSelect so that
    • when shouldDragSelect === true downed is being set through the event-listeners set inside the effect
    • and if shouldDragSelect === false downed is being set whenever one of Select's children is being clicked.

Besides that I also added shouldDragSelect as a dependency of the effect, before this commit the multiple or box props weren't included, which could have caused bugs too.

Checklist

  • Ready to be merged

When the props `multiple` and `box` are defined, `downed` is being
set through eventListeners set on the window inside an effect.
If they are not set, `downed` before this commit was never set,
which caused `onChange` to never run.

To solve this bug I add a condition `shouldDragSelect = multiple && box`
a conditional event-listeners on `<group/>` in case `!shouldDragSelect`
so that when `shouldDragSelect` `down` is being set through the
event-listeners set inside the effect, and if `!shouldDragSelect` it
is being set whenever one of Select's children is being clicked.
Before commit the effect relying on `shouldDragSelect` did not include it in its dependencies.
Neither did the code before this branch, so I am unsure if this was a conscious act or not,
but I believe it could cause a bug where one of the props is changed but event-listeners are not properly cleaned up.

besides this I return `undefined` instead of `null` in case `shouldDragSelect` in `<group/>` event-listeners
@bigmistqke bigmistqke changed the title fix: <Select/> when !multiple || !box` fix: <Select/> when !multiple || !box Aug 16, 2023
@vercel
Copy link

vercel bot commented Aug 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drei ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2023 3:09pm

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 4839f66:

Sandbox Source
lucid-snowflake-nnqd5d Configuration
Ground reflections and video textures Configuration
arc-x-pmndrs-colors Configuration

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.

None yet

1 participant