Semantic-ui-react: Dropdown: closing Dropdown inside a Modal by clicking Escape also closes Modal

Created on 3 Oct 2018  路  7Comments  路  Source: Semantic-Org/Semantic-UI-React

Bug Report

There is no way to prevent an event triggered by a Dropdown to affect a Modal containing it. Reproduces with Escape, Enter and other keys/events.

Steps

  1. Create a search+selection Dropdown inside a Modal
  2. Try start searching some value in the Dropdown and hit Escape to close it

Expected Result

Dropdown is closed, Modal is open

Actual Result

Modal is closed

Version

0.82.5

Testcase

https://codesandbox.io/s/9y8vzn4nvr

bug

Most helpful comment

Sure it will work. But I want it to close on escape, just not when Dropdown is open and users want the Dropdown to close, not the Modal. Same applies to Enter key - users want to choose item in the Dropdown, not to submit the form in Modal

All 7 comments

馃憢 Thanks for opening your first issue here! If you're reporting a 馃悶 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

Hey @vkramskikh , try to add this on modal component: closeOnEscape={false}

It should work :)

Sure it will work. But I want it to close on escape, just not when Dropdown is open and users want the Dropdown to close, not the Modal. Same applies to Enter key - users want to choose item in the Dropdown, not to submit the form in Modal

I think you should handle escape event by props onClose
something like this
https://codesandbox.io/s/mjrlq64w8x

Modal could have any Component, So It can't decide to ignore which escape event come from

@vkramskikh , I had a similar problem. If a certain input field inside my modal was visible, I wanted to close it with escape. Otherwise I wanted the modal to close as normal with escape.
My solution was to use the modal as controlled component, then set closeOnEscape={false} on the modal, then inside of it I listened for the escape click event and if the input field was visible I just closed that one, otherwise I called the function I passed in that closed the modal.

<Modal 
    open={this.state.newGroupModalOpen}
    closeOnEscape={false}>
         <Modal.Content>
               <NewModifierGroup 
                      cancel={this.closeModifierModal.bind(this)}
               />
         </Modal.Content>                    
</Modal>

NewModifierGroup:


    componentDidMount(){
        document.addEventListener("keydown", this.catchEscape);
    }

    componentWillUnmount(){
        document.removeEventListener("keydown", this.catchEscape); 
    }

    catchEscape(e){        
        if(e.key == 'Escape'){
            if(this.state.showNewModifierInput){
                this.setState({
                    ...this.state,
                    showNewModifierInput: false
                })
            } else {
                this.props.cancel()
            }
        }        
    }

There has been no activity in this thread for 180 days. While we care about every issue and we鈥檇 love to see this fixed, the core team鈥檚 time is limited so we have to focus our attention on the issues that are most pressing. Therefore, we will likely not be able to get to this one.

However, PRs for this issue will of course be accepted and welcome!

If there is no more activity in the next 180 days, this issue will be closed automatically for housekeeping. To prevent this, simply leave a reply here. Thanks!

I think that adding stopPropagation on the dropdown escape event will prevent this, no?

Here:https://github.com/Semantic-Org/Semantic-UI-React/blob/master/src/modules/Dropdown/Dropdown.js#L203

Was this page helpful?
0 / 5 - 0 ratings