Trying to enhance my learning, I am currently working on developing an autocomplete feature. Referencing this example for guidance:
https://codesandbox.io/s/8lyp733pj0.
Encountering two main issues with this implementation:
1.) Conflict between mouse hover and keypress. When using the keyboard to navigate through the list, the active item gets highlighted. Simultaneously, if using the mouse, another item may get highlighted resulting in multiple selections.
2.) Upon selecting an item by pressing enter, the input field correctly fills with the selected text. However, upon pressing enter again, it changes the text back to the index 0 item instead.
Seeking assistance in resolving these dilemmas. Already experimented with hover and focus in CSS but without achieving desired results.
Potential solutions under consideration:
- Disabling mouse events when a keyboard is being used, and vice versa.
- Considering removing this.setState({activeSuggestion: 0}) for the enter event.
Appreciate any help provided - grasping the nuances of state management with React is proving to be quite challenging.