-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Remove tags with the Delete key #33822
[Autocomplete] Remove tags with the Delete key #33822
Conversation
|
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.
Good idea, thanks!
It would be great to include this new functionality in tests.
case 'Delete': | ||
if (multiple && !readOnly && inputValue === '' && value.length > 0) { | ||
const index = focusedTag === -1 ? value.length - 1 : focusedTag; | ||
const newValue = value.slice(); | ||
newValue.splice(index, 1); | ||
handleValue(event, newValue, 'removeOption', { | ||
option: value[index], | ||
}); | ||
} | ||
break; |
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.
Looks like the code is duplicated. Could you add the case 'Delete'
to the previous case block?
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.
Awesome, thank you! I will do that asap.
Thanks! During testing, I found one behavior I'm not sure about. When no tags are selected (the cursor is visible), pressing Delete removes the last tag (just like the Backspace key does). This may be a bit confusing, as Delete usually removes a character to the right of the visible cursor, not to the left as in this case. So, after all, we may need a separate case for The behavior for deleting selected tags looks fine. Could you please merge/rebase on the latest master? We've had some issues with uploading regression tests' screenshots in the past, but they have been fixed, and the current master should work fine. |
…and it will delete chip to the right
I updated it where Video update (you can't see but in beginning I was hitting the delete key to show it won't work) 😅 autocomplete.mov |
…m/sfavello/material-uii into autocomplete-accessibility-delete merge
👍 It does work well now when the cursor is behind tags. But when a tag is focused, Delete should delete the focused tag itself, not the next one. |
…m/sfavello/material-uii into autocomplete-accessibility-delete update branch
I completely misunderstood. 😅 My apologies. I fixed it where it will not delete a chip when the cursor is behind the tags and when on DEMO autocompleteDemo.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.
Now the behavior is correct, thanks!
I found one possible improvement to do in the code.
@@ -850,6 +850,16 @@ export default function useAutocomplete(props) { | |||
}); | |||
} | |||
break; | |||
case 'Delete': | |||
if (multiple && !readOnly && inputValue === '' && value.length > 0 && focusedTag !== -1) { | |||
const index = focusedTag === -1 ? value.length - 1 : focusedTag; |
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.
No need to check if focusedTag === -1
, as the outer if
handles this already.
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.
Awesome, thank you! I appreciate it. I went in and made the change. 😄
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 your work!
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.
There's some issue with tests - would you mind checking it?
So I checked the 3. failing tests
|
Try merging in the latest master. It should help to solve the problems with Argos and E2E tests. it('does not delete any tags with the delete key when no tag is highlighted', () => {
const handleChange = spy();
const options = ['one', 'two'];
render(
<Autocomplete
defaultValue={options}
options={options}
onChange={handleChange}
renderInput={(params) => <TextField {...params} autoFocus />}
multiple
/>,
);
const textbox = screen.getByRole('combobox');
fireEvent.keyDown(textbox, { key: 'Delete' });
expect(handleChange.callCount).to.equal(0);
expect(textbox).toHaveFocus();
}); |
Added test and updated the branch. That fixed the problem. 🥳 . Thank you for your patience. I appreciate it. |
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.
Looks good to me. Thanks again for your contribution!
Oh nice, I didn't think about the Del key. When I was on Windows, I always struggled to reach this key on my keyboard. |
Co-authored-by: Sylvialynn Favello <sylvia-favello@docker.com>
Co-authored-by: Sylvialynn Favello <sylvia-favello@docker.com>
This was to solve the issue that Autocomplete does not handle the functionality of the delete key, more specifically the forward delete key. When creating a Chip and the chip is on hover, it passes on the impression that you can use either the backspace key or the delete key to eliminate the chip. It's best to stay consistent and include the functionality of a delete key.
React.Autocomplete.component.-.Material.UI.-.Google.Chrome.2022-08-06.13-09-14_Trim.mp4