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

[Autocomplete] Custom Popper with "Action Option" keyboard support #45224

Open
mogrady88 opened this issue Feb 5, 2025 · 5 comments
Open

[Autocomplete] Custom Popper with "Action Option" keyboard support #45224

mogrady88 opened this issue Feb 5, 2025 · 5 comments
Assignees
Labels
component: autocomplete This is the name of the generic UI component, not the React module! new feature New feature or request package: material-ui Specific to @mui/material waiting for 👍 Waiting for upvotes

Comments

@mogrady88
Copy link
Contributor

mogrady88 commented Feb 5, 2025

Hey,

I'm trying to implement an Autocomplete with a custom Popper and an "action Item" at the top of the list. The "action item" is a ListItemButton. This renders just fine, which is great, but I'm running into issues trying to add keyboard support to this implementation. The user should be able to Tab to the "action item" in order to interact with it but when I press Tab the Autocomplete closes.

I have not found any way to keep the menu open when I press the Tab key. Do you have any ideas on how I could achieve this?

Implementation:
Image

Popper Code:
Image

onKeyDown Handler Code (handleBaseKeyDown is mapped to the onKeyDown prop on Autocomplete):
Image

Search keywords:

@github-actions github-actions bot added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 5, 2025
@mj12albert
Copy link
Member

mj12albert commented Feb 6, 2025

onKeyDown Handler Code (handleBaseKeyDown is mapped to the onKeyDown prop on Autocomplete)

@mogrady88 Instead of preventDefault(), does this work:

event.defaultMuiPrevented = true;

Reference: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/useAutocomplete/useAutocomplete.js#L760-L767

@mj12albert mj12albert added package: material-ui Specific to @mui/material component: autocomplete This is the name of the generic UI component, not the React module! labels Feb 6, 2025
@mj12albert mj12albert changed the title MUI Autocomplete Custom Popper with "Action Option" keyboard support [Autocomplete] Custom Popper with "Action Option" keyboard support Feb 6, 2025
@mj12albert mj12albert added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 6, 2025
@mogrady88
Copy link
Contributor Author

Hey @mj12albert that doesnt work either unfortunately. I wasnt sure if this was due to any onKeyDown logic. I almost need a way to mimic whatever happens when you force the open prop to true

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Feb 6, 2025
@mogrady88
Copy link
Contributor Author

mogrady88 commented Feb 6, 2025

For reference there is this codesandbox that's got a similar setup to mine. Pressing Tab closes the menu instead of navigating to the button

@DiegoAndai DiegoAndai self-assigned this Feb 6, 2025
@DiegoAndai DiegoAndai added new feature New feature or request waiting for 👍 Waiting for upvotes and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 6, 2025
@DiegoAndai DiegoAndai added this to the Material UI with Base UI milestone Feb 6, 2025
@DiegoAndai
Copy link
Member

DiegoAndai commented Feb 6, 2025

Hey @mogrady88, thanks for the report!

Sadly, this is not supported at the moment, similar to the Select component #26356.

I added the waiting for 👍🏼 label so the community can vote for this new feature. If you want to see this implemented, please add a 👍🏼 reaction to the issue's description.

In the meantime, if you or anyone is trying to find a workaround, I would recommend looking at Autocomplete's implementation, mimicking the Popper and its children's structure, and using slots.popper to replace it. Similarly to what you've tried in https://codesandbox.io/p/sandbox/compassionate-butterfly-f4rn8z?file=%2Fdemo.tsx%3A46%2C26.

@mogrady88
Copy link
Contributor Author

Ok, thank you Diego! Ill take a look the workaround in the meantime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! new feature New feature or request package: material-ui Specific to @mui/material waiting for 👍 Waiting for upvotes
Projects
None yet
Development

No branches or pull requests

3 participants