Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/mui-material/src/Autocomplete/Autocomplete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,18 @@ describe('<Autocomplete />', () => {
expect(handleOpen.callCount).to.equal(1);
});

it('should not focus the input when clicking helper text', async () => {
const { user } = render(
<Autocomplete
options={['one']}
renderInput={(params) => <TextField {...params} helperText="Some help" />}
/>,
);

await user.click(screen.getByText('Some help'));
expect(screen.getByRole('combobox')).not.toHaveFocus();
});

it('does not clear the textbox on Escape', () => {
const handleChange = spy();
render(
Expand Down
8 changes: 8 additions & 0 deletions packages/mui-material/src/useAutocomplete/useAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,10 @@ function useAutocomplete(props) {
if (!event.currentTarget.contains(event.target)) {
return;
}
// Don't interfere with interactions outside the input area (e.g. helper text)
if (anchorEl && !anchorEl.contains(event.target)) {
return;
}
if (event.target.getAttribute('id') !== id) {
event.preventDefault();
}
Expand All @@ -1166,6 +1170,10 @@ function useAutocomplete(props) {
if (!event.currentTarget.contains(event.target)) {
return;
}
// Don't interfere with interactions outside the input area (e.g. helper text)
if (anchorEl && !anchorEl.contains(event.target)) {
return;
}
inputRef.current.focus();

if (
Expand Down
Loading