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

[DataGrid] Don't listen in the capture phase #1156

Closed
wants to merge 1 commit into from

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Mar 3, 2021

Opened it for experimentation. I don't understand this thread: #1025 (comment). I want to see if the CI is green and play with the built demos. Related to #1157.

@@ -199,8 +199,8 @@ export function useEvents(gridRootRef: React.RefObject<HTMLDivElement>, apiRef:
return () => {
logger.debug('Clearing all events listeners');
api.publishEvent(GRID_UNMOUNT);
gridRootElem.removeEventListener(GRID_CLICK, onClickHandler, { capture: true });
gridRootElem.removeEventListener(GRID_MOUSE_HOVER, onHoverHandler, { capture: true });
gridRootElem.removeEventListener(GRID_CLICK, onClickHandler);
Copy link
Member

Choose a reason for hiding this comment

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

the event bubble up so if you attach them to the root then they won't fire when you click an element within it.

Copy link
Member Author

@oliviertassinari oliviertassinari Mar 3, 2021

Choose a reason for hiding this comment

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

I don't understand the reasoning. This argument would be valid if we were listening to an event that doesn't bubble, like the scroll event or focus. click/mouseover bubble.

Regarding the outcome, the demos in https://deploy-preview-1156--material-ui-x.netlify.app/components/data-grid/selection/#data-grid-selection seems to work correctly and the tests are green.

Copy link
Member

Choose a reason for hiding this comment

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

checkout #1158

Copy link
Member Author

@oliviertassinari oliviertassinari Mar 3, 2021

Choose a reason for hiding this comment

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

Before we move forward with #1158, could you report one concrete bug with the current changes? This could then be added as a regression test case for the future. The notion seems important enough so we sync with reality.

Copy link
Member Author

Choose a reason for hiding this comment

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

the event bubble up so if you attach them to the root then they won't fire when you click an element within it.

A counterexample that demonstrates this affirmation is false: https://codesandbox.io/s/nifty-bush-brmqw?file=/src/App.tsx

Copy link
Member

Choose a reason for hiding this comment

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

Yes I agree I got really confused here with the bubbling. Just need to check the params are still ok but I think they should be

Copy link
Member Author

@oliviertassinari oliviertassinari Mar 3, 2021

Choose a reason for hiding this comment

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

I personally think that #1158 would be even better than #1156. It removes the capture phase, which should be more intuitive for developers and integrate with the synthetic event system of React, perfect for them for using custom event logic 👌

Copy link
Member

Choose a reason for hiding this comment

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

The nice thing about #1158 is that it could use the helper to generate the params...
The bad thing is atm we generate a new function at every render so react.memo is not possible

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, what do you recommend as the best next step?

Copy link
Member

Choose a reason for hiding this comment

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

I will refactor a bit more and merge #1158 with the comments above

@dtassone dtassone closed this Mar 5, 2021
@oliviertassinari oliviertassinari deleted the capture branch March 5, 2021 10:50
@oliviertassinari oliviertassinari added the component: data grid This is the name of the generic UI component, not the React module! label Jan 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants