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.

Using the up/down arrow keys to select one of the options does not fire onChange

See original GitHub issue

Version

5.0.0.rc3 and then downgraded to 4.2.3 (both act the same way)

Steps to reproduce

TypeAhead is filled with an array of objects, labelKey is set to the name property. One mouse click inside focuses the input and the options drop down. Use the arrow keys to select one of the options. Note in console.log (in the onChange handler) that the event does not fire.

// this is a snippet
    const onKeyDown = (event: any): void => {
    if (event.keyCode === 13) {
      // TODO: Using the arrow keys to select an item does not fire an onTypeAheadChange
      if(selectedTypeAheadItem!==undefined){
        //use the item and close the popup
        onSelectContext(selectedTypeAheadItem)
      }
    }
  }

  const onTypeAheadChange = (event: any): void => {
    // the selection is an array, but we only want 1
    console.log(event)
    setSelectedTypeAheadItem(event[0])
  }
            <Typeahead
                options={typeAheadOptions}
                labelKey='name'
                clearButton={false}
                id='context-menu-typeahead'
                onKeyDown={onKeyDown}
                onChange={onTypeAheadChange}
                placeholder={t('Search compound by typing')}
              />

Expected Behavior

onChange should be called for each arrow key event

Actual Behavior

onChange is not called

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ericgiocommented, Feb 7, 2021

@ayush-mandowara-bst: Yours sounds like an unrelated issue. If you think you’re encountering a bug, please open a separate issue with relevant code and repro steps. A working sandbox is ideal.

@srigi: As a workaround, you can pass a render function as a child of the typeahead component that receives the internal state. You can use activeItem to get the currently highlighted item.

<Typeahead ... >
  {({ activeItem }) => {
    // Do something with the value.
  }}
</Typeahead>
1reaction
jhvandervencommented, Jun 12, 2020

I now think you are completely right. I was misled by my use case. I have the typeahead in a context menu and the second enter is needed to indicate that the user wants to use the value in the input rather than one of the other items. Maybe I should rethink my GUI. Sorrry for the trouble and thanks for answering.

Read more comments on GitHub >

github_iconTop Results From Across the Web

126379 - Select (size=1) onChange not called using down ...
With radio buttons the onchange event fires *before* focus is lost. ... two reasons that onchange is not fired by using the arrow...
Read more >
[jQuery] select .change event not firing on up/down arrow press
The change event fires fine when the user changes the select box using the mouse, but not when the keyboard up/down arrow keys...
Read more >
Javascript onChange arrow keys - Stack Overflow
Upon this option element being picked (either through a click, or through unfocusing the element after changing its value, or through a menu ......
Read more >
Up and down arrow keys not working to change answer to ...
The arrow keys will not move As a result, I would tab through all the elements of the page until I get to...
Read more >
3347 - onChange event is not fired when an option is selected ...
I often trigger a postback or an ajax load onchange of a select box. If this does not work using keyboard then the...
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