primereact
primereact copied to clipboard
Dropdown: unselects option when loses focus
Describe the bug
The dropdown loses the selected option when the component loses focus. The event onKeyDown
is coming with an undefined value, resetting the field. The event onClick
works fine.
Reproducer
https://stackblitz.com/edit/vitejs-vite-yy9mcw
PrimeReact version
10.5.1
React version
18.x
Language
TypeScript
Build / Runtime
Vite
Browser(s)
No response
Steps to reproduce the behavior
- Open the Stackblitz link;
- Select an option in the dropdown;
- Press tab;
The dropdown option you selected is cleared.
Expected behavior
The selected option should remain.
Hmm the hook form example on the showcase is working? https://primereact.org/dropdown/#hookform
Also I just disabled Strict Mode and it looks like its working: https://stackblitz.com/edit/vitejs-vite-8uvnxd?file=src%2Fmain.tsx
So its a strict mode issue i think.
In your link, for me, it is still happening. You need to test it twice. The first selection works fine.
Yep you are right now it works the first time but not subsequent times.
Here I added console.log
to the events:
https://stackblitz.com/edit/vitejs-vite-8v5uqj?file=src%2FApp.tsx
The problem is the onKeyDown
event.
Yep
OK fixed it.