blueprint icon indicating copy to clipboard operation
blueprint copied to clipboard

Select - handleClick in a MenuItem ignores "shouldDismissPopover"

Open rccoe opened this issue 4 years ago • 2 comments

Environment

  • Package version(s): 3.22.3
  • Browser and OS versions: Chrome, MacOS Catalina

If possible, link to a minimal repro (fork this code sandbox): https://codesandbox.io/s/blueprint-sandbox-e7yqv

Steps to reproduce

  1. Create a Select component
  2. Set up an itemRenderer with MenuItems that have shouldDismissPopover=false and uses the handleClick function from the itemProps
  3. Open select and click on a menu item

Actual behavior

The popover closes when you click on a menuItem. This is because handleClick sets "isOpen" to false on the Select.

Expected behavior

The popover should stay open, since shouldDismissPopover is false;

Possible solution

Don't set isOpen=false in the handleClick function.

As a workaround, I've started using the onItemSelect function directly in the itemRenderer rather than handleClick, which keeps the popover open.

rccoe avatar Mar 06 '20 15:03 rccoe

looks like it is still a bug with the latest versions: https://codesandbox.io/s/blueprint-sandbox-forked-shq49?file=/src/SelectExample.tsx

related: https://github.com/palantir/blueprint/issues/4695

adidahiya avatar May 20 '21 17:05 adidahiya

Still an issue in Blueprint 4.x, with Select2: https://codesandbox.io/s/blueprint-sandbox-forked-z2kbnr?file=/src/SelectExample.tsx

Fix should be as easy as checking for Classes.POPOVER_DISMISS on the nearest Classes.MENU_ITEM on the event target in this line: https://github.com/palantir/blueprint/blob/f8415b517c307e7c7fe0c76acdfbfdeae332e233/packages/select/src/components/select/select2.tsx#L268

adidahiya avatar Jul 20 '22 20:07 adidahiya