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

[material-ui][Chip] Fix focus issue related with the Escape event #41578

Open
wants to merge 9 commits into
base: next
Choose a base branch
from

Conversation

shrilsharma
Copy link

fixes #40510

@mui-bot
Copy link

mui-bot commented Mar 20, 2024

Netlify deploy preview

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 04e9e48

@danilo-leal danilo-leal changed the title Fix/chip-focus-issue [material-ui][Chip] Fix focus issue related with the Escape event Mar 20, 2024
@danilo-leal danilo-leal added component: chip This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material labels Mar 20, 2024
@DiegoAndai DiegoAndai removed the request for review from siriwatknp March 25, 2024 15:36
@DiegoAndai
Copy link
Member

Thanks for working on this @shrilsharma.

This change does make sense to me as it gets the clickable Chip closer to a button:

  • Focus is not lost when the Escape key is pressed
  • Focus goes back accordingly when closing a Modal, Dialog, Drawer

But I'm hesitant as the functionality has been there forever. This is the farthest back I could track the blur() call: chaudharykiran@943f95f#diff-d1439e644fd94d980426ac362fcc36489ba82e228bab753e9a37dd96c61fded4R117.

What do you think @zanivan @mnajdova?

@shrilsharma
Copy link
Author

Hi @DiegoAndai

What I understand from the code is that it was intentionally made to lose focus on the escape key down.

@DiegoAndai
Copy link
Member

DiegoAndai commented Mar 27, 2024

What I understand from the code is that it was intentionally made to lose focus on the escape key down.

Yes, you're correct. I'm wondering (and asking) if that's a behavior we wish to modify. As I mentioned, it makes sense to me to change it and make it closer to a button, but I want to discuss it with @zanivan and @mnajdova as the functionality is a longstanding one.

@zanivan
Copy link
Contributor

zanivan commented Mar 27, 2024

What do you think @zanivan @mnajdova?

Unless there's a specific reason I'm unaware of, the chip's behavior should be similar to the button's in this case.

@DiegoAndai
Copy link
Member

@mnajdova do you see any reason not to go forward with this change? Is there any historical context of why the Chip losing focus with the escape key behavior was implemented?

@mnajdova
Copy link
Member

@mnajdova do you see any reason not to go forward with this change? Is there any historical context of why the Chip losing focus with the escape key behavior was implemented?

I am not aware of it, the logic seems to be here from the creation of the component. I would recommend checking if there are some regressions with the Autocomplete, as the component is used when the multiple prop is set.

@DiegoAndai
Copy link
Member

I checked the multiple Autocomplete use case, and it's working as expected. The blur of the chip inside it when "Escape" is pressed (and actually, when any key except "ArrowLeft" and "ArrowRight" is pressed) is handled here: https://github.com/mui/material-ui/blob/next/packages/mui-base/src/useAutocomplete/useAutocomplete.js#L799-L802

I think we can move forward with this change. May I ask you to remove the if clause entirely, @shrilsharma, instead of commenting on the blur call? Thanks!

@shrilsharma
Copy link
Author

@DiegoAndai, I have removed the if block as you suggested.

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

👏🏼

@DiegoAndai DiegoAndai self-requested a review April 24, 2024 18:55
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

Hey @shrilsharma, thanks for updating the PR. May I ask you to update the failing tests as well? Thanks!

Copy link
Member

@DiegoAndai DiegoAndai 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 updating the test @shrilsharma!

I think the last thing left to do is to add this to the v6 migration guide: https://github.com/mui/material-ui/blob/next/docs/data/material/migration/migration-v5/migration-v5.md

May I ask you to add a short explanation about the change, why it was needed (to make the chip consistent with buttons), and a short example on how to implement the previous behaviour (probably providing a custom onKeyUp handler)

We should also add a codemod, but that might take a little more time. Let me know if you're up to implementing the codemod, otherwise I can take it separately.

@shrilsharma
Copy link
Author

Hi @DiegoAndai, I have updated the migration doc and I think we can add the codemod separately.

Copy link
Member

@DiegoAndai DiegoAndai 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 updating the PR @shrilsharma

I've reconsidered and think we shouldn't add a codemod, as it would be an edge case and anticipating the user's component architecture would be very complicated.

I've updated the copy a bit, and asked @samuelsycamore for a review on the guide specifically.

docs/data/material/migration/migration-v5/migration-v5.md Outdated Show resolved Hide resolved
docs/data/material/migration/migration-v5/migration-v5.md Outdated Show resolved Hide resolved
docs/data/material/migration/migration-v5/migration-v5.md Outdated Show resolved Hide resolved
Signed-off-by: Diego Andai <diego@mui.com>
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: chip This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[material-ui][Chip] Focus issue with Modal/Drawer/Menu
6 participants