jpmorganchase / salt-ds

React UI components built with a focus on accessibility, customisation and ease-of-use
https://www.saltdesignsystem.com
Apache License 2.0
109 stars 78 forks source link

Dropdown / Combo Box would be nice to not trigger blur event on mouse selection #3578

Open origami-z opened 2 weeks ago

origami-z commented 2 weeks ago

Area

UI Components

The problem

When using Dropdown and Combo Box in forms, it's common to set validation during onBlur event to check whether the field is left blank but required, i.e., passing onBlur event to form controls. In current implementation, mouse down event on the list control options would trigger onBlur, resulted a false negative user feedback.

See below example when using them with react-hook-form

https://stackblitz.com/edit/salt-template-h2lymn?file=App.tsx,package.json

The solution

Do not trigger blur event on the main form control when selecting options using mouse.

Alternatives and examples

Above behavior also made it hard to implement custom ag grid editors, when stopEditingWhenCellsLoseFocus is set to true. Possible workaround: add additional classname ag-custom-component-popup to the popup element. Demo: https://stackblitz.com/edit/salt-ag-grid-theme-t9gyex?file=App.jsx

Are you a JPMorgan Chase & Co. employee?

joshwooding commented 2 weeks ago

Duplicates #3453, but since this one has a reproduction I'll close the other