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

[Autocomplete] Listen for click on the root element #36369

Merged
merged 19 commits into from
Apr 4, 2023

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Feb 28, 2023

closes #36364

preview: https://deploy-preview-36369--material-ui.netlify.app/joy-ui/react-autocomplete/

joy UI working video

screen-recording-2023-03-04-at-42306-pm_yYbkTH3w.mov

material ui Working video

https://www.loom.com/share/5386e85fa34049b2b481e44abfdade42

@sai6855 sai6855 marked this pull request as draft February 28, 2023 11:53
@mui-bot
Copy link

mui-bot commented Feb 28, 2023

Netlify deploy preview

https://deploy-preview-36369--material-ui.netlify.app/

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 85125ce

@sai6855 sai6855 marked this pull request as ready for review March 1, 2023 04:01
@zannager zannager added the component: autocomplete This is the name of the generic UI component, not the React module! label Mar 1, 2023
@zannager zannager requested a review from siriwatknp March 1, 2023 10:55
@marcpachecog
Copy link

@sai6855 Your changes have introduced another bug:

Grabacion.de.pantalla.2023-03-01.a.las.15.37.01.mov

@sai6855
Copy link
Contributor Author

sai6855 commented Mar 1, 2023

@sai6855 Your changes have introduced another bug:

Nice catch, I'll check

@sai6855
Copy link
Contributor Author

sai6855 commented Mar 4, 2023

@sai6855 Your changes have introduced another bug:

@marcpachecog Fixed the bug you found out and i've updated PR description with new video.

@siriwatknp @ZeeshanTamboli PR is ready for review now

Comment on lines 1029 to 1031
if (event.currentTarget === event.target) {
handleInputMouseDown();
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it should also focus on the input as well, otherwise I can't close the popup on blur in this case. I mouse down on the border and then mouse up on one of the options, after that I cannot close the popup when click outside of the autocomplete.

Screen.Recording.2566-03-11.at.15.03.18.mov

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@siriwatknp moved all logic to onClick, now bug you found is fixed.

}
};

// Focus the input when interacting with the combobox
const handleClick = () => {
const handleClick = (event) => {
inputRef.current.focus();
Copy link
Member

@oliviertassinari oliviertassinari Mar 15, 2023

Choose a reason for hiding this comment

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

To see if it makes sense to use this bug as an opportunity to fix this line. Focusing on click no sense per #29381 (comment)

Copy link
Contributor Author

@sai6855 sai6855 Mar 17, 2023

Choose a reason for hiding this comment

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

@oliviertassinari i had changed logic, since previous logic wasn't working for material-ui Autocomplete. With updated logic, i don't know if the your proposed fix is relevant to fix in this PR.

handleRootOnClick(event);
}
if (event.currentTarget === event.target && handleInputMouseDown) {
handleInputMouseDown(event as React.MouseEvent<HTMLInputElement, MouseEvent>);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

handleInputMouseDown expects event to be coming from input but here we have access to event of div element. that's why had to cast the type

@sai6855 sai6855 requested a review from siriwatknp March 17, 2023 12:41
@@ -439,6 +441,16 @@ const Autocomplete = React.forwardRef(function Autocomplete(
externalForwardedProps: other,
ownerState,
getSlotProps: getRootProps,
additionalProps: {
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
Copy link
Contributor Author

@sai6855 sai6855 Mar 18, 2023

Choose a reason for hiding this comment

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

this onClick overrides onClick from https://github.com/mui/material-ui/blob/master/packages/mui-base/src/useAutocomplete/useAutocomplete.js#L1084 , hence onClick coming from useAutoComplete is called again here.

@@ -571,6 +573,11 @@ const Autocomplete = React.forwardRef(function Autocomplete(inProps, ref) {
ref: setAnchorEl,
className: classes.inputRoot,
startAdornment,
onClick: (event) => {
if (event.target === event.currentTarget) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check to make sure, handleInputMouseDown is called only when user clicks on input element.

if (handleRootOnClick) {
handleRootOnClick(event);
}
if (event.currentTarget === event.target && handleInputMouseDown) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Check to make sure, handleInputMouseDown is called only when user clicks on input element.

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Thanks for the fix!

@@ -766,6 +766,15 @@ describe('Joy <Autocomplete />', () => {
});
});

it('should open popup when clicked on borders of input element', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the description matches what you are testing. It should be : 'should open popup when clicked on the root element'.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mnajdova updated in this commit 85125ce

@@ -967,6 +967,23 @@ describe('<Autocomplete />', () => {
});
});

it('should open popup when clicked on borders of input element', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated in this commit 85125ce

@mnajdova mnajdova changed the title [Autocomplete] Listen for click on border [Autocomplete] Listen for click on the root element Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete 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.

[Joy] Autocomplete not opening when clicking in the borders
8 participants