I'm currently working on translating our current Dart Web UI project to Polymer.dart. We use Bootstrap 3 for the front-end styling and many web animations (e.g. dropdown menus, modals, tooltips).
However after I translated one Web UI component into Polymer, all the Bootstrap JavaScript stopped working for the sub component, since it was now encapsulated in the ShadowDOM. To access an element in the ShadowDOM from Dart I have to use the shadowRoot field, and from JavaScript in Chrome I have to use the webkitShadowRoot property, but still I can't get a single dropdown menu to work properly.
Firstly, after calling the dropdown('toggle') API in bootstrap, the dropdown menu appears but never goes away. Also, it seems impossible to detect which link is triggered by the click event since the event is fired on the window level. This means I can't find which dropdown menu to display.
Does anyone have experience using twitter-bootstrap and Polymer together?
I managed to get bootstrap.js working for my polymer components by adding the lightdom attribute to their definition.
And the host HTML could look like this:
Please note: Using the lightdom attribute will replace your components from the shadow DOM to the light DOM, which can cause conflicts between your component's styling and the existing styles of the global context.
The related discussion: https://groups.google.com/a/dartlang.org/forum/#!topic/web-ui/ps6b9wlg1Vk
Based on the discussion I wasn't a 100% sure if the lightdom modifier will stay the standard way to achieve this kind of functionality for polymer components. Perhaps the authors could comment on that?
The problem as pointed out in the other answers is the shadow dom. Bootstrap does not see the elements in there, and thus can not do its magic. You can disable the shadowdom and apply the author styles like this:
You will need to remove the shadowdom for all parent elements as well.
WARNING: You will use the on-click event handler by using lightdom :(
Your questison is about the Polymer.dart port, but applies to Polymer.js devs as well :)
As you point out, the issue is with Bootstrap's JS. It doesn't know about ShadowDOM and attempts to fetch nodes from the DOM using global selectors. For example, in bootstrap-carousel.js, I see things like:
We explored using Bootstrap components inside of Polymer a little bit ago: https://github.com/Polymer/more-elements/tree/stable/Bootstrap
The most interesting to you would be
<bs-accordion-item>
(Demo)The process is basically to wrap Bootstrap stuff inside a custom element and call into their APIs.
For the CSS: if you include their stylesheet inside your element, things should generally work:
Keep in mind that if bootstrap.css is coming from a CDN, it needs to be CORS-enabled for the polyfills to work properly. This requirement goes away when native HTML Imports lands.