question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Autocomplete] Add ability to override/compose key down events in autocomplete

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Developer should have ability to override or compose default onKeyDown functionality

Examples 🌈

Currently when i specify custom onKeyDown prop i’ll get default functionality executed and only then the one i provided.

It makes not possible to override or compose default functionality for specific key pressed.

What i want to be able to do is:

<Autocomplete {...props} onKeyDown={(event, originalHandler) => {
  if (['Enter', 'ArrowLeft'].includes(event.key)) {
    customHandler(event);
  } else {
    originalHandler(event)
  }
}}>

Motivation 🔦

Motivation is to have ability to override default behaviour for specific event Keys.

Possible use case:

  • Need to be able to select options in dropdown with Space key and on Enter key drop down should close and blur out
const onKeyDown = (event, originalFn) => {
  switch(event.key) {
    case 'Enter':
       submitChangesAndFocusOut();
       brake;
    case 'Space':
      selectFocusedItem();
      brake;
     default:
        originalFn(event);
  }
}

<Autocomplete {...props} onKeyDown={onKeyDown}>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

3reactions
oliviertassinaricommented, Mar 1, 2020

@ivan-jelev Interesting, we have seen a similar concern raised in #19500. What do you think of my proposal at https://github.com/mui-org/material-ui/issues/19500#issuecomment-580867606? I think that we could move forward with it 😃.

1reaction
marcosvega91commented, Apr 26, 2020

Yes right as i said in the previous comment i didn’t read the case well.

So i can create a PR for this 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Autocomplete] Add ability to override/compose key down ...
Currently when i specify custom onKeyDown prop i'll get default functionality executed and only then the one i provided. It makes not possible ......
Read more >
Overriding keypress event during autocomplete select event
I was using autocomplete, and I wanted to jump specifically to another field after the complete event. So I set focus(). But, the...
Read more >
Jetpack Compose – A Simple Opiniated AutoCompleteTextView
So I decided to write my own AutoCompleteTextView to achieve similar behavior. Breaking Down AutoCompleteTextView. At it's core, we rely on two ...
Read more >
AutoCompleteTextView - Android Developers
android:dropDownAnchor, View to anchor the auto-complete dropdown to. ... Defines whether this view reacts to context click events.
Read more >
Rich text box with mentions and hashtags - Autocomplete
Unlike most autocomplete experiences, the Twitter compose box doesn't process a ... algoliasearch # or yarn add @algolia/autocomplete-core ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found