3
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
Code distributed by Google as part of the polymer project is also
8
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
11
<link rel="import" href="../polymer/polymer.html">
12
<link rel="import" href="../iron-overlay-behavior/iron-overlay-behavior.html">
13
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
14
<link rel="import" href="../paper-styles/default-theme.html">
15
<link rel="import" href="../paper-styles/typography.html">
16
<link rel="import" href="../paper-styles/shadow.html">
21
Use `Polymer.PaperDialogBehavior` and `paper-dialog-shared-styles.html` to implement a Material Design
24
For example, if `<paper-dialog-impl>` implements this behavior:
28
<div>Dialog body</div>
30
<paper-button dialog-dismiss>Cancel</paper-button>
31
<paper-button dialog-confirm>Accept</paper-button>
35
`paper-dialog-shared-styles.html` provide styles for a header, content area, and an action area for buttons.
36
Use the `<h2>` tag for the header and the `buttons` class for the action area. You can use the
37
`paper-dialog-scrollable` element (in its own repository) if you need a scrolling content area.
39
Use the `dialog-dismiss` and `dialog-confirm` attributes on interactive controls to close the
40
dialog. If the user dismisses the dialog with `dialog-confirm`, the `closingReason` will update
41
to include `confirmed: true`.
45
The following custom properties and mixins are available for styling.
47
Custom property | Description | Default
48
----------------|-------------|----------
49
`--paper-dialog-background-color` | Dialog background color | `--primary-background-color`
50
`--paper-dialog-color` | Dialog foreground color | `--primary-text-color`
51
`--paper-dialog` | Mixin applied to the dialog | `{}`
52
`--paper-dialog-title` | Mixin applied to the title (`<h2>`) element | `{}`
53
`--paper-dialog-button-color` | Button area foreground color | `--default-primary-color`
57
This element has `role="dialog"` by default. Depending on the context, it may be more appropriate
58
to override this attribute with `role="alertdialog"`.
60
If `modal` is set, the element will set `aria-modal` and prevent the focus from exiting the element.
61
It will also ensure that focus remains in the dialog.
65
@polymerBehavior Polymer.PaperDialogBehavior
68
Polymer.PaperDialogBehaviorImpl = {
78
* If `modal` is true, this implies `no-cancel-on-outside-click`, `no-cancel-on-esc-key` and `with-backdrop`.
88
'_modalChanged(modal, _readied)'
92
'tap': '_onDialogClick'
96
// Only now these properties can be read.
97
this.__prevNoCancelOnOutsideClick = this.noCancelOnOutsideClick;
98
this.__prevNoCancelOnEscKey = this.noCancelOnEscKey;
99
this.__prevWithBackdrop = this.withBackdrop;
102
_modalChanged: function(modal, readied) {
104
this.setAttribute('aria-modal', 'true');
106
this.setAttribute('aria-modal', 'false');
109
// modal implies noCancelOnOutsideClick, noCancelOnEscKey and withBackdrop.
110
// We need to wait for the element to be ready before we can read the
111
// properties values.
117
this.__prevNoCancelOnOutsideClick = this.noCancelOnOutsideClick;
118
this.__prevNoCancelOnEscKey = this.noCancelOnEscKey;
119
this.__prevWithBackdrop = this.withBackdrop;
120
this.noCancelOnOutsideClick = true;
121
this.noCancelOnEscKey = true;
122
this.withBackdrop = true;
124
// If the value was changed to false, let it false.
125
this.noCancelOnOutsideClick = this.noCancelOnOutsideClick &&
126
this.__prevNoCancelOnOutsideClick;
127
this.noCancelOnEscKey = this.noCancelOnEscKey &&
128
this.__prevNoCancelOnEscKey;
129
this.withBackdrop = this.withBackdrop && this.__prevWithBackdrop;
133
_updateClosingReasonConfirmed: function(confirmed) {
134
this.closingReason = this.closingReason || {};
135
this.closingReason.confirmed = confirmed;
139
* Will dismiss the dialog if user clicked on an element with dialog-dismiss
140
* or dialog-confirm attribute.
142
_onDialogClick: function(event) {
143
// Search for the element with dialog-confirm or dialog-dismiss,
144
// from the root target until this (excluded).
145
var path = Polymer.dom(event).path;
146
for (var i = 0; i < path.indexOf(this); i++) {
147
var target = path[i];
148
if (target.hasAttribute && (target.hasAttribute('dialog-dismiss') || target.hasAttribute('dialog-confirm'))) {
149
this._updateClosingReasonConfirmed(target.hasAttribute('dialog-confirm'));
151
event.stopPropagation();
159
/** @polymerBehavior */
160
Polymer.PaperDialogBehavior = [Polymer.IronOverlayBehavior, Polymer.PaperDialogBehaviorImpl];