Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input onClick doesn't work when input is inside DropdownButton or ButtonToolbar #62

Closed
andjarnic opened this issue Apr 8, 2014 · 9 comments

Comments

@andjarnic
Copy link

I am showing a login form with username and password input boxes when a user clicks on a Login button in a DropdownButton which is in a ButtonToolbar. I added onClick to put in a handler to prevent default and stop propagation because currently clicking on the input box causes the menu to close, so I can't type into user input boxes.

              <ul className="nav navbar-nav">
                <li><Link href='/'>Home</Link></li>
                <li><Link href='/register'>Register</Link></li>
              </ul>

              <ul className="nav navbar-nav navbar-right">
                <li>
                    <ButtonToolbar>
                        <DropdownButton bsStyle='default' bsSize='large' title='Login'>
                            <form id="loginForm" accept-charset="UTF-8">
                                <input id="login_username" style={inputStyle} onClick={this.inputClick} type="text" name="username" placeholder="Username" size="30" />
                                <input id="login_password" style={inputStyle} onClick={this.inputClick} type="password" name="password" placeholder="Password" size="30" />
                                <button type="button" className="btn btn-primary" onClick={this.login} style={inputStyle}>Login</button>
                            </form>
                        </DropdownButton>
                    </ButtonToolbar>
                </li>
              </ul>
            </div>
          </nav>
@stevoland
Copy link
Contributor

Hmm, I think this is the same behaviour as the Bootstrap component. I'm not sure we should change it. I think your workaround is reasonable.

You could just add one handler to the form like: <form onClick={this.killClick} />.

@andjarnic
Copy link
Author

Yes.. it is.. the way they handle it is a jquery hack to be honest. The problem I am facing is adding onClick to the is being ignored. When I click on the input box that shows up in the drop down, nothing happens. onFocus works though... but it doesn't prevent the pop-down menu from disappearing as soon as I click on the input box. I'll try putting it on the form element, see if that helps.

On Tuesday, April 8, 2014 7:18 AM, Stephen J. Collings notifications@github.com wrote:

Hmm, I think this is the same behaviour as the Bootstrap component. I'm not sure we should change it. I think your workaround is reasonable.
You could just add one handle to the form like:

.

Reply to this email directly or view it on GitHub.

@stevoland
Copy link
Contributor

Ah, ok, I think I misunderstood. I'll look into this.

@stevoland
Copy link
Contributor

Sorry, just got round to looking at this. So at the moment it's expected that children are MenuItems. If you wrap your form in a MenuItem the handler will fire but you'll have an unwanted anchor in your markup that you could work around with CSS.

I think we should support your use case by rendering a div instead of a ul if the children aren't MenuItems.

@hedgerh
Copy link
Contributor

hedgerh commented Aug 8, 2015

I looked into this issue, and was unable to reproduce. It appears that the click behavior of the DropdownButton component was addressed in #86.

            <ul className="nav navbar-nav navbar-right">
              <li>
                <ButtonToolbar>
                    <DropdownButton bsStyle='default' bsSize='large' title='Login' onClick={ this.handleClick }>
                        <form id="loginForm" accept-charset="UTF-8">
                            <input id="login_username" style={inputStyle} onClick={this.inputClick} type="text" name="username" placeholder="Username" size="30" />
                            <input id="login_password" style={inputStyle} onClick={this.inputClick} type="password" name="password" placeholder="Password" size="30" />
                            <button type="button" className="btn btn-primary" onClick={this.login} style={inputStyle}>Login</button>
                        </form>
                    </DropdownButton>
                </ButtonToolbar>
              </li>
            </ul>

with click handlers:

  handleClick(e) {
    console.log('handleClick');
  };

  inputClick(e) {
    e.stopPropagation();
  };

The input click handler was triggered, and the event did not propagate up to the DropdownButton.

@taion
Copy link
Member

taion commented Aug 10, 2015

@hedgerh Thank you! Closing this issue for now, then, especially with the dropdown rework.

@taion taion closed this as completed Aug 10, 2015
@rulyotano
Copy link

Why is this is closed?? I still getting the same issue/error!

@jquense
Copy link
Member

jquense commented Jan 26, 2016

@rulyotano because inputs aren't supported in dropdown menus. The current API though does allow you make a custom menu that does support it

@rulyotano
Copy link

Ok, so the solution is creating your own drop down, and handle a lot of things that custom drop down doesn't, like closing on click out. What is the reason why inputs are not supported! Thanks for answering.

AustinEast pushed a commit to AustinEast/react-bootstrap that referenced this issue Feb 8, 2017
aryad14 pushed a commit to aryad14/react-bootstrap that referenced this issue Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants