1

I am trying to use Bootstrap with an application based on Polymer Web Components. Based on this question: Bootstrap.js not working in Polymer components I can generally get Bootstrap mostly working by including it from within a component's template so that it can see the shadow DOM content.

However, even with this it appears that functionality like dropdowns and the navbar-toggle still do not work. Is there a workaround for this?

I created a JSFiddle that tries to demonstrate this. The global dropdown will work only if the Bootstrap JS/CSS is not included in the polymer component's . The component's dropdown will partially be styled correctly, but not actually function if the Bootstrap JS/CSS is included in the polymer component's . This will also break the functionality of the global dropdown.

http://jsfiddle.net/u72xk3kk/

<link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html">

<nav class="navbar-default" role="navigation">
    <article class="container-fluid">
        <header class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <span class="navbar-brand">NavBar</span>
        </header>
        <section class="collapse navbar-collapse">
            <ul class="nav navbar-nav">
                <li><a>Foo</a></li>
                <li><a>Bar</a></li>
            </ul>
        </section>
    </article>
</nav>

    This dropdown works fine if the bootstrap js and css includes are not done in the component's template:<br/>
    <div id="works" class="dropdown">
        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
            Global Dropdown
            <span class="caret"></span>
        </button>
        <ul id="blarg" class="dropdown-menu" role="menu">
            <li>Foo</li>
            <li>Bar</li>
        </ul>
    </div>     

<polymer-element name="my-component">
    <template>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
        <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"/>
        <div class="dropdown">
        <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">
            Component Dropdown <span class="caret"></span>
        </button>
        <ul class="dropdown-menu" role="menu">
            <li>Eggs</li>
            <li>Spam</li>
        </ul>
    </div>   
    <content/>
    </template>
    <script>
        Polymer({});
    </script>
</polymer-element>

    This dropdown is partially styled ok, but doesn't actually work even if the Bootstrap js and css is included in the polymer component templae:<br/>
<my-component/>
Community
  • 1
  • 1
drarmstr
  • 680
  • 1
  • 8
  • 16

1 Answers1

0
        ready: function () {
            $('.dropdown-toggle').dropdown();
        }

I included the js file ONLY in the page header, and not in the components in my project, and i have working dropdowns in the page and components both. bootstrap/js/dropdown.js"

Kajackdfw
  • 1,511
  • 1
  • 9
  • 4