| 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 `core-dropdown-menu` works together with `core-dropdown` and `core-selector` 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 `core-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. | |
| 20 | |
| 21 Example: | |
| 22 | |
| 23 <core-dropdown-menu label="Choose a pastry"> | |
| 24 <core-dropdown class="dropdown"> | |
| 25 <core-selector> | |
| 26 <core-item label="Croissant"></core-item> | |
| 27 <core-item label="Donut"></core-item> | |
| 28 <core-item label="Financier"></core-item> | |
| 29 <core-item label="Madeleine"></core-item> | |
| 30 </core-selector> | |
| 31 </core-dropdown> | |
| 32 </core-dropdown-menu> | |
| 33 | |
| 34 @group Polymer Core Elements | |
| 35 @element core-dropdown-menu | |
| 36 @extends core-dropdown-base | |
| 37 @status unstable | |
| 38 @homepage github.io | |
| 39 --> | |
| 40 | |
| 41 <link href="../polymer/polymer.html" rel="import"> | |
| 42 <link href="../core-a11y-keys/core-a11y-keys.html" rel="import"> | |
| 43 <link href="../core-dropdown/core-dropdown-base.html" rel="import"> | |
| 44 <link href="../core-focusable/core-focusable.html" rel="import"> | |
| 45 <link href="../core-icon/core-icon.html" rel="import"> | |
| 46 <link href="../core-icons/core-icons.html" rel="import"> | |
| 47 | |
| 48 <polymer-element name="core-dropdown-menu" extends="core-dropdown-base" relative
layout inline horizontal center tabindex="0"> | |
| 49 <template> | |
| 50 | |
| 51 <style> | |
| 52 :host { | |
| 53 background-color: #fff; | |
| 54 } | |
| 55 | |
| 56 :host([disabled]) { | |
| 57 color: #a8a8a8; | |
| 58 } | |
| 59 | |
| 60 #label { | |
| 61 overflow: hidden; | |
| 62 white-space: nowrap; | |
| 63 text-overflow: ellipsis; | |
| 64 } | |
| 65 </style> | |
| 66 | |
| 67 <core-a11y-keys target="{{}}" keys="enter space" on-keys-pressed="{{toggleOver
lay}}"></core-a11y-keys> | |
| 68 | |
| 69 <div flex auto id="label">{{selectedItemLabel || label}}</div> | |
| 70 <core-icon id="arrow" icon="{{opened ? openedIcon : closedIcon}}"></core-icon> | |
| 71 | |
| 72 <content></content> | |
| 73 | |
| 74 </template> | |
| 75 <script> | |
| 76 | |
| 77 (function() { | |
| 78 | |
| 79 var p = { | |
| 80 | |
| 81 publish: { | |
| 82 | |
| 83 /** | |
| 84 * A label for the control. The label is displayed if no item is selected. | |
| 85 * | |
| 86 * @attribute label | |
| 87 * @type string | |
| 88 * @default 'Select an item' | |
| 89 */ | |
| 90 label: 'Select an item', | |
| 91 | |
| 92 /** | |
| 93 * The icon to display when the drop-down is opened. | |
| 94 * | |
| 95 * @attribute openedIcon | |
| 96 * @type string | |
| 97 * @default 'arrow-drop-up' | |
| 98 */ | |
| 99 openedIcon: 'arrow-drop-up', | |
| 100 | |
| 101 /** | |
| 102 * The icon to display when the drop-down is closed. | |
| 103 * | |
| 104 * @attribute closedIcon | |
| 105 * @type string | |
| 106 * @default 'arrow-drop-down' | |
| 107 */ | |
| 108 closedIcon: 'arrow-drop-down' | |
| 109 | |
| 110 }, | |
| 111 | |
| 112 selectedItemLabel: '', | |
| 113 | |
| 114 overlayListeners: { | |
| 115 'core-overlay-open': 'openAction', | |
| 116 'core-activate': 'activateAction', | |
| 117 'core-select': 'selectAction' | |
| 118 }, | |
| 119 | |
| 120 activateAction: function(e) { | |
| 121 this.opened = false; | |
| 122 }, | |
| 123 | |
| 124 selectAction: function(e) { | |
| 125 var detail = e.detail; | |
| 126 if (detail.isSelected) { | |
| 127 this.selectedItemLabel = detail.item.label || detail.item.textContent; | |
| 128 } else { | |
| 129 this.selectedItemLabel = ''; | |
| 130 } | |
| 131 } | |
| 132 | |
| 133 }; | |
| 134 | |
| 135 Polymer.mixin2(p, Polymer.CoreFocusable); | |
| 136 Polymer(p); | |
| 137 | |
| 138 })(); | |
| 139 | |
| 140 </script> | |
| 141 </polymer-element> | |
| OLD | NEW |