OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved. |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 6 Code distributed by Google as part of the polymer project is also |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 8 --> |
| 9 |
| 10 <!-- |
| 11 |
| 12 `paper-dropdown-menu` works together with `paper-dropdown` and `core-menu` to |
| 13 implement a drop-down menu. The currently selected item is displayed in the |
| 14 control. If no item is selected, the `label` is displayed instead. |
| 15 |
| 16 The child element with the class `dropdown` will be used as the drop-down |
| 17 menu. It should be a `paper-dropdown` or other overlay element. You should |
| 18 also provide a `core-selector` or other selector element, such as `core-menu`, |
| 19 in the drop-down. You should apply the class `menu` to the selector element. |
| 20 |
| 21 Example: |
| 22 |
| 23 <paper-dropdown-menu label="Your favorite pastry"> |
| 24 <paper-dropdown class="dropdown"> |
| 25 <core-menu class="menu"> |
| 26 <paper-item>Croissant</paper-item> |
| 27 <paper-item>Donut</paper-item> |
| 28 <paper-item>Financier</paper-item> |
| 29 <paper-item>Madeleine</paper-item> |
| 30 </core-menu> |
| 31 </paper-dropdown> |
| 32 </paper-dropdown-menu> |
| 33 |
| 34 This example renders a drop-down menu with 4 options. |
| 35 |
| 36 @group Paper Elements |
| 37 @element paper-dropdown-menu |
| 38 @extends core-dropdown-base |
| 39 @status unstable |
| 40 @homepage github.io |
| 41 --> |
| 42 |
| 43 <!-- |
| 44 Fired when an item's selection state is changed. This event is fired both |
| 45 when an item is selected or deselected. The `isSelected` detail property |
| 46 contains the selection state. |
| 47 |
| 48 @event core-select |
| 49 @param {Object} detail |
| 50 @param {boolean} detail.isSelected true for selection and false for deselectio
n |
| 51 @param {Object} detail.item the item element |
| 52 --> |
| 53 <link href="../polymer/polymer.html" rel="import"> |
| 54 |
| 55 <link href="../core-a11y-keys/core-a11y-keys.html" rel="import"> |
| 56 <link href="../core-dropdown/core-dropdown-base.html" rel="import"> |
| 57 <link href="../core-focusable/core-focusable.html" rel="import"> |
| 58 <link href="../core-icon/core-icon.html" rel="import"> |
| 59 <link href="../core-icons/core-icons.html" rel="import"> |
| 60 <link href="../paper-shadow/paper-shadow.html" rel="import"> |
| 61 |
| 62 <style shim-shadowdom> |
| 63 html /deep/ #paper-dropdown-menu-dropdown { |
| 64 margin: 12px; |
| 65 overflow: visible; |
| 66 } |
| 67 |
| 68 html /deep/ #paper-dropdown-menu-dropdown #menu { |
| 69 padding: 8px 0; |
| 70 margin: 0; |
| 71 } |
| 72 |
| 73 html /deep/ #paper-dropdown-menu-dropdown .menu-container { |
| 74 overflow: auto; |
| 75 max-height: 100%; |
| 76 max-width: 100%; |
| 77 } |
| 78 </style> |
| 79 |
| 80 <polymer-element name="paper-dropdown-menu" extends="core-dropdown-base" relativ
e layout inline horizontal center tabindex="0"> |
| 81 <template> |
| 82 |
| 83 <style> |
| 84 :host { |
| 85 -moz-user-select: none; |
| 86 -ms-user-select: none; |
| 87 -webkit-user-select: none; |
| 88 user-select: none; |
| 89 cursor: pointer; |
| 90 padding: 0.5em 0 0.25em; |
| 91 margin: 0.75em 0; |
| 92 border-bottom: 1px solid #757575; |
| 93 outline: none; |
| 94 } |
| 95 |
| 96 #label, #arrow { |
| 97 color: #757575; |
| 98 } |
| 99 |
| 100 #label { |
| 101 overflow: hidden; |
| 102 white-space: nowrap; |
| 103 text-overflow: ellipsis; |
| 104 } |
| 105 </style> |
| 106 |
| 107 <core-a11y-keys target="{{}}" keys="enter space" on-keys-pressed="{{toggleOver
lay}}"></core-a11y-keys> |
| 108 |
| 109 <div flex auto id="label">{{selectedItemLabel || label}}</div> |
| 110 <core-icon id="arrow" icon="{{opened ? openedIcon : closedIcon}}"></core-icon> |
| 111 |
| 112 <content></content> |
| 113 |
| 114 </template> |
| 115 <script> |
| 116 |
| 117 (function() { |
| 118 |
| 119 var p = { |
| 120 |
| 121 publish: { |
| 122 |
| 123 /** |
| 124 * A label for the control. The label is displayed if no item is selected. |
| 125 * |
| 126 * @attribute label |
| 127 * @type string |
| 128 * @default 'Select an item' |
| 129 */ |
| 130 label: 'Select an item', |
| 131 |
| 132 /** |
| 133 * The icon to display when the drop-down is opened. |
| 134 * |
| 135 * @attribute openedIcon |
| 136 * @type string |
| 137 * @default 'arrow-drop-up' |
| 138 */ |
| 139 openedIcon: 'arrow-drop-up', |
| 140 |
| 141 /** |
| 142 * The icon to display when the drop-down is closed. |
| 143 * |
| 144 * @attribute closedIcon |
| 145 * @type string |
| 146 * @default 'arrow-drop-down' |
| 147 */ |
| 148 closedIcon: 'arrow-drop-down' |
| 149 |
| 150 }, |
| 151 |
| 152 selectedItemLabel: '', |
| 153 |
| 154 overlayListeners: { |
| 155 'core-overlay-open': 'openAction', |
| 156 'core-activate': 'activateAction', |
| 157 'core-select': 'selectAction' |
| 158 }, |
| 159 |
| 160 activateAction: function(e) { |
| 161 this.opened = false; |
| 162 }, |
| 163 |
| 164 selectAction: function(e) { |
| 165 var detail = e.detail; |
| 166 if (detail.isSelected) { |
| 167 this.selectedItemLabel = detail.item.label || detail.item.textContent; |
| 168 } else { |
| 169 this.selectedItemLabel = ''; |
| 170 } |
| 171 } |
| 172 |
| 173 }; |
| 174 |
| 175 Polymer.mixin2(p, Polymer.CoreFocusable); |
| 176 Polymer(p); |
| 177 |
| 178 })(); |
| 179 |
| 180 </script> |
| 181 </polymer-element> |
OLD | NEW |