-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Conversation
Netlify deploy previewhttps://deploy-preview-36369--material-ui.netlify.app/ Bundle size report |
@sai6855 Your changes have introduced another bug: Grabacion.de.pantalla.2023-03-01.a.las.15.37.01.mov |
Nice catch, I'll check |
@marcpachecog Fixed the bug you found out and i've updated PR description with new video. @siriwatknp @ZeeshanTamboli PR is ready for review now |
if (event.currentTarget === event.target) { | ||
handleInputMouseDown(); | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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>); |
There was a problem hiding this comment.
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
@@ -439,6 +441,16 @@ const Autocomplete = React.forwardRef(function Autocomplete( | |||
externalForwardedProps: other, | |||
ownerState, | |||
getSlotProps: getRootProps, | |||
additionalProps: { | |||
onClick: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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', () => { |
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -967,6 +967,23 @@ describe('<Autocomplete />', () => { | |||
}); | |||
}); | |||
|
|||
it('should open popup when clicked on borders of input element', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
There was a problem hiding this comment.
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
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