Prevent paper-dialog from automatically closing

末鹿安然 提交于 2019-12-06 08:12:34

You don't need to remove affirmative/dismissive attributes as they are used for layout. Polymer dialog docs are wrong (I've opened a GH issue) the default value for closeSelector is '[dismissive],[affirmative]' and not "", you just need to set closeSelector to "" and it won't close the dialog on clicking the buttons.

You just need to remove the affirmative attribute from the button then you have full control of the behavior.

app-element.dart

import 'package:polymer/polymer.dart';

import 'dart:html';
import 'package:paper_elements/paper_dialog.dart';
/**
 * A Polymer app-element element.
 */
@CustomTag('app-element')

class AppElement extends PolymerElement {

  /// Constructor used to create instance of AppElement.
  AppElement.created() : super.created() {
  }

  void openClickHandler(Event e) {
    print(e);
    ($['autom_desc_dialog'] as PaperDialog).opened = true;
  }

  void closeClickHandler(Event e){
    if(true /* some condition */) {
      ($['autom_desc_dialog'] as PaperDialog).opened = false;
    }
  }

}

app_element.html

<!-- import polymer-element's definition -->
<link rel="import" href="../../packages/polymer/polymer.html">
<link rel="import" href="../../packages/paper_elements/paper_dialog.html">
<link rel="import" href="../../packages/paper_elements/paper_button.html">

<polymer-element name="app-element">
  <template>
    <style>
      :host {
        display: block;
      }
    </style>
    <paper-dialog id="autom_desc_dialog" autoCloseDisabled>
      <div>paper dialog</div>
      <paper-button id="automatizar" autofocus label="close" on-click="{{closeClickHandler}}"></paper-button>
    </paper-dialog>

    <paper-button id="open" autofocus label="open" on-click="{{openClickHandler}}"></paper-button>
  </template>
  <script type="application/dart" src="app_element.dart"></script>
</polymer-element>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!