material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Autocomplete] Bring Accessibility to Autocomplete with Delete key

Open sfavello opened this issue 3 years ago • 1 comments

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.

https://user-images.githubusercontent.com/90116354/183264769-7e5f870e-bab3-41b6-a86d-fa3935869c9a.mp4

sfavello avatar Aug 06 '22 20:08 sfavello

Messages
:book: Netlify deploy preview: https://deploy-preview-33822--material-ui.netlify.app/

Details of bundle changes

Generated by :no_entry_sign: dangerJS against 8d3da585fd25a95afeeea1d9008bc46e85fd7e20

mui-bot avatar Aug 06 '22 20:08 mui-bot

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 'Delete' and run the code only if focusedTag !== -1.

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.

michaldudak avatar Oct 13 '22 07:10 michaldudak

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 'Delete' and run the code only if focusedTag !== -1.

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.

I updated it whereDelete key will not delete the value at the end but will delete the value to the right when it's on a focusedTag. 😄

Video update (you can't see but in beginning I was hitting the delete key to show it won't work) 😅 _From around 0 to 5 seconds is the test to make sure the delete will only run when focusedTag !== -1

https://user-images.githubusercontent.com/90116354/196053868-8d4cb460-87a7-4795-8747-680203b7c43e.mov

sfavello avatar Oct 16 '22 19:10 sfavello

:+1: 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.

michaldudak avatar Oct 28 '22 11:10 michaldudak

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 focusedTag it will delete the tag that's on focus. I also updated the test to reflect the changes. 😄

DEMO

https://user-images.githubusercontent.com/90116354/198842720-73f8f656-b183-4dc1-b85a-5c757c877cbe.mov

sfavello avatar Oct 29 '22 16:10 sfavello

So I checked the 3. failing tests

  1. argos states that there is 8 differences detected in the screenshots
  2. the e2e test is failing in a material-docs.spec.ts where the icon AcUnit is not visible. I'm still researching around why my changes could have possibly effected these two things, but I'll keep investigating.
  3. The other failing test was fixed. 😄

sfavello avatar Nov 01 '22 23:11 sfavello

Try merging in the latest master. It should help to solve the problems with Argos and E2E tests. Could you also add another unit test that would verify if no tags are deleted if they are not highlighted? Something along these lines:

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();
});

michaldudak avatar Nov 02 '22 08:11 michaldudak

Try merging in the latest master. It should help to solve the problems with Argos and E2E tests. Could you also add another unit test that would verify if no tags are deleted if they are not highlighted? Something along these lines:

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.

sfavello avatar Nov 04 '22 22:11 sfavello

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.

oliviertassinari avatar Nov 15 '22 14:11 oliviertassinari