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

feat(hooks): remove mouse and touch events on unmount #1581

Merged
merged 2 commits into from Mar 13, 2024

Conversation

silviuaavram
Copy link
Collaborator

@silviuaavram silviuaavram commented Mar 10, 2024

What:
Remove the mouse and touch event handlers on unmount.

Why:
The previous implementation was removing the handlers and adding new ones on each isOpen change.

How:
Removed the isOpen dependency from the hook and moved the logic to the callback passed by useCombobox and useSelect.

Checklist:

  • Documentation
  • Tests
  • TypeScript Types
  • Flow Types
  • Ready to be merged

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (32d675d) to head (1c2da99).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #1581   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           18        18           
  Lines         1755      1749    -6     
  Branches       529       524    -5     
=========================================
- Hits          1755      1749    -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@silviuaavram silviuaavram merged commit 7997f76 into master Mar 13, 2024
2 checks passed
@silviuaavram silviuaavram deleted the feat/mouse-touch-event-removers branch March 13, 2024 08:14
Copy link

🎉 This PR is included in version 8.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isOpen, environment])
// eslint-disable-next-line react-hooks/exhaustive-deps -- refs don't change
}, [environment, handleBlur])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change broke the blur behaviour. Now using @testing-library/user-event, when we clears the input (and don't focus out) it triggers the blur and unselect the selected item:

await user.clear(input)

In my implementation, I am using the stateReducer to unselected the selected value of a combobox on blur if the input value is empty:

case useCombobox.stateChangeTypes.InputBlur:
        if (allowCustomValue) return changes

        if (state.inputValue === '') {
          setSelectedItem(null)

          return { ...changes, selectedItem: null }
        }

It's breaking the tests because I no longer have a way to clear the input without triggering the blur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants