While using Bootstrap-Vue, how do you prevent a b-dropdown from closing when clicking on a nested b-input component?

烈酒焚心 提交于 2019-12-24 01:37:42

问题


I'm pretty sure I just don't understand how to implement Vue's Event Modifiers. According to that documentation, all I have to do is add this:

<!-- the click event's propagation will be stopped -->
<a v-on:click.stop="doThis"></a>

Here's how I interpreted the example into my pug code:

b-dropdown(text="Actions")
  b-dropdown-item
    b-form(inline)
      .row
        .col
          b-input(@click.stop='' placeholder="#123")
          b-button(:href='printCheck' variant="primary") Print Check

It looks pretty simple, however it's not working as expected. If you need more supporting info, just ask. And feel free to tweak the title; I wasn't sure if my question is a vue, bootstrap-vue, or javascript question.

Thanks for your time in advance,
Kevin


回答1:


Since you're clicking on a component you should combine .native with .stop modifiers like so :

 b-input(@click.native.stop='' placeholder="#123")

if you're using a simple HTML element like input you could use only .stop modifier:

 input(@click.stop='' placeholder="#123")



回答2:


You can now use the new <b-dropdown-form> sub-component for placing input fields into dropdowns.

You should avoid placing input controls inside <b-dropdown-item> (which renders an <a> as it's root element), or <b-dropdown-item-button> (which renders a <button> as its root element). HTML5 doesn't like interactive elements inside <a> or <button> elements.

<b-dropdown-form> does not auto-close the dropdown when it is clicked.



来源:https://stackoverflow.com/questions/53639701/while-using-bootstrap-vue-how-do-you-prevent-a-b-dropdown-from-closing-when-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!