salesforce / design-system-react

Salesforce Lightning Design System for React
https://design-system-react-site.herokuapp.com/
BSD 3-Clause "New" or "Revised" License
915 stars 416 forks source link

Popover not trapping Escape key when rendered inside the Modal component #3031

Closed bxiao closed 2 years ago

bxiao commented 2 years ago

When a Popover component is used inside a Modal component and if the popover is open, pressing the Escape key closes both the popover and the modal.

Expected behavior: Pressing Escape key when the popover is open should only close the popover. Modal should remain open.

welcome[bot] commented 2 years ago

Thanks for opening your first issue! :wave: If you have found this library helpful, please star it. A maintainer will try to respond within 7 days. If you haven’t heard anything by then, please bump this thread.

interactivellama commented 2 years ago

This line may help also. In the Combobox PR fix, this is what stops the event from bubbling https://github.com/salesforce/design-system-react/blob/master/utilities/key-callbacks.js#L16

if (stopPropagation) {
            EventUtil.trapEvent(event);
        }

So something like this should do it in https://github.com/salesforce/design-system-react/blob/master/utilities/keyboard-navigable-dialog.js#L46

case KEYS.ESCAPE:
    if (isOpen) {
        toggleOpen();
        EventUtil.trapEvent(event);
    }
break;