Bootstrap.js not working in Polymer components

后端 未结 3 1507
孤独总比滥情好
孤独总比滥情好 2020-12-09 00:21

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 me

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 00:33

    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:

    import 'package:polymer/polymer.dart';
    import 'dart:html';
    
    @CustomTag('main-messages')
    class MainMessagesElement extends PolymerElement {
      MainMessagesElement.created() : super.created();
    
      //This enables the styling via bootstrap.css
      bool get applyAuthorStyles => true;
      //This enables the bootstrap javascript to see the elements
      @override
      Node shadowFromTemplate(Element template) {
        var dom = instanceTemplate(template);
        append(dom);
        shadowRootReady(this, template);
        return null; // no shadow here, it's all bright and shiny
      }   
    }
    

    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 :(

提交回复
热议问题