primereact icon indicating copy to clipboard operation
primereact copied to clipboard

Dropdown: unselects option when loses focus

Open sandrocsimas opened this issue 1 year ago • 7 comments

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. image image

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

  1. Open the Stackblitz link;
  2. Select an option in the dropdown;
  3. Press tab;

The dropdown option you selected is cleared.

Expected behavior

The selected option should remain.

sandrocsimas avatar Feb 23 '24 14:02 sandrocsimas

Hmm the hook form example on the showcase is working? https://primereact.org/dropdown/#hookform

melloware avatar Feb 23 '24 14:02 melloware

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.

melloware avatar Feb 23 '24 14:02 melloware

In your link, for me, it is still happening. You need to test it twice. The first selection works fine.

sandrocsimas avatar Feb 23 '24 14:02 sandrocsimas

Yep you are right now it works the first time but not subsequent times.

melloware avatar Feb 23 '24 14:02 melloware

Here I added console.log to the events: https://stackblitz.com/edit/vitejs-vite-8v5uqj?file=src%2FApp.tsx

image

The problem is the onKeyDown event.

sandrocsimas avatar Feb 23 '24 14:02 sandrocsimas

Yep

melloware avatar Feb 23 '24 15:02 melloware

OK fixed it.

melloware avatar Feb 23 '24 15:02 melloware