0

Assume to have this Datalist element in a React component:

const MyComp = () => {
  return (<>
    <input list="list-name">
    <datalist id="list-name">
      <option key="1" value="Option 1" />
      <option key="2" value="Option 2" />
      <option key="3" value="Option 3" />
      <option key="4" value="Option 4" />
      <option key="5" value="Option 5" />
    </datalist>
  </>)
}

onClick or onSelect events on the options or on the datalist are not triggered. How do i intercept the option selection event?

1 Answer 1

0

as displayed in the following stackblitz snippet:

https://stackblitz.com/edit/vitejs-vite-xcxa9q?file=src%2FApp.tsx

the selection can be intercepted via the onChange / onKeyUp / onKeyDown events.

Where usually the 'key' value returns the value of the pressed key, when clicking on the option we see Unidentified as the .key property value

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.