Skip to content

Customize Combobox "Enter" keypress handling #1280

Answered by calthomson
calthomson asked this question in Help
Discussion options

You must be logged in to vote

In the end I was able to capture the Enter key press events with a global event listener after all.

To be honest, I'm not sure exactly what I did differently but I believe I was just running into some unrelated issues regarding the keypress events. In the end, this worked fine for me, I was able to add my own key press behavior on top of the regular "select on Enter" behavior that comes with Combobox:

const handleKeyUp = (event: KeyboardEvent) => {
  if (event.key === 'Enter') {
    console.log("Enter pressed");
  }
}

useEffect(() => {
  document.addEventListener('keyup', handleKeyUp);

  return () => {
    document.removeEventListener('keyup', handleKeyUp);
  };
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by calthomson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant