Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Unified Diff: lib/src/paper-dropdown-menu/paper-dropdown-menu.html

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: lib/src/paper-dropdown-menu/paper-dropdown-menu.html
diff --git a/lib/src/paper-dropdown-menu/paper-dropdown-menu.html b/lib/src/paper-dropdown-menu/paper-dropdown-menu.html
index 092ce11eebfe316eb3659dd99ef1bfa872bbde70..c02d9b5848f578121c40f93a45a03fecc0e9ae23 100644
--- a/lib/src/paper-dropdown-menu/paper-dropdown-menu.html
+++ b/lib/src/paper-dropdown-menu/paper-dropdown-menu.html
@@ -19,8 +19,12 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-selector/iron-selectable.html">
+<link rel="import" href="../iron-form-element-behavior/iron-form-element-behavior.html">
+<link rel="import" href="../iron-validatable-behavior/iron-validatable-behavior.html">
<!--
+Material design: [Dropdown menus](https://www.google.com/design/spec/components/buttons.html#buttons-dropdown-buttons)
+
`paper-dropdown-menu` is similar to a native browser select element.
`paper-dropdown-menu` works with selectable content. The currently selected
item is displayed in the control. If no item is selected, the `label` is
@@ -43,6 +47,9 @@ Example:
This example renders a dropdown menu with 4 options.
+Similarly to using `iron-select`, `iron-deselect` events will cause the
+current selection of the `paper-dropdown-menu` to be cleared.
+
### Styling
The following custom properties and mixins are also available for styling:
@@ -74,6 +81,12 @@ respectively.
text-align: left;
cursor: pointer;
+ /* NOTE(cdata): Both values are needed, since some phones require the
+ * value to be `transparent`.
+ */
+ -webkit-tap-highlight-color: rgba(0,0,0,0);
+ -webkit-tap-highlight-color: transparent;
+
--paper-input-container-input: {
overflow: hidden;
white-space: nowrap;
@@ -99,15 +112,17 @@ respectively.
}
paper-ripple {
- top: 20px;
- left: 8px;
- bottom: 16px;
- right: 8px;
+ top: 12px;
+ left: 0px;
+ bottom: 8px;
+ right: 0px;
@apply(--paper-dropdown-menu-ripple);
}
paper-menu-button {
+ display: block;
+ padding: 0;
@apply(--paper-dropdown-menu-button);
}
@@ -131,10 +146,12 @@ respectively.
disabled="[[disabled]]"
no-animations="[[noAnimations]]"
on-iron-select="_onIronSelect"
+ on-iron-deselect="_onIronDeselect"
opened="{{opened}}">
<div class="dropdown-trigger">
<paper-ripple></paper-ripple>
<paper-input
+ invalid="[[invalid]]"
readonly
disabled="[[disabled]]"
value="[[selectedItemLabel]]"
@@ -170,7 +187,9 @@ respectively.
behaviors: [
Polymer.IronControlState,
- Polymer.IronButtonState
+ Polymer.IronButtonState,
+ Polymer.IronFormElementBehavior,
+ Polymer.IronValidatableBehavior
],
properties: {
@@ -182,13 +201,15 @@ respectively.
selectedItemLabel: {
type: String,
notify: true,
- computed: '_computeSelectedItemLabel(selectedItem)'
+ readOnly: true
},
/**
* The last selected item. An item is selected if the dropdown menu has
* a child with class `dropdown-content`, and that child triggers an
* `iron-select` event with the selected `item` in the `detail`.
+ *
+ * @type {?Object}
*/
selectedItem: {
type: Object,
@@ -197,6 +218,17 @@ respectively.
},
/**
+ * The value for this element that will be used when submitting in
+ * a form. It is read only, and will always have the same value
+ * as `selectedItemLabel`.
+ */
+ value: {
+ type: String,
+ notify: true,
+ readOnly: true
+ },
+
+ /**
* The label for the dropdown.
*/
label: {
@@ -262,6 +294,10 @@ respectively.
'aria-haspopup': 'true'
},
+ observers: [
+ '_selectedItemChanged(selectedItem)'
+ ],
+
attached: function() {
// NOTE(cdata): Due to timing, a preselected value in a `IronSelectable`
// child will cause an `iron-select` event to fire while the element is
@@ -304,6 +340,15 @@ respectively.
},
/**
+ * A handler that is called when `iron-deselect` is fired.
+ *
+ * @param {CustomEvent} event An `iron-deselect` event.
+ */
+ _onIronDeselect: function(event) {
+ this._setSelectedItem(null);
+ },
+
+ /**
* A handler that is called when the dropdown is tapped.
*
* @param {CustomEvent} event A tap event.
@@ -320,12 +365,16 @@ respectively.
* @param {Element} selectedItem A selected Element item, with an
* optional `label` property.
*/
- _computeSelectedItemLabel: function(selectedItem) {
+ _selectedItemChanged: function(selectedItem) {
+ var value = '';
if (!selectedItem) {
- return '';
+ value = '';
+ } else {
+ value = selectedItem.label || selectedItem.textContent.trim();
}
- return selectedItem.label || selectedItem.textContent.trim();
+ this._setValue(value);
+ this._setSelectedItemLabel(value);
},
/**
@@ -340,9 +389,18 @@ respectively.
// derived from the metrics of elements internal to `paper-input`'s
// template. The metrics will change depending on whether or not the
// input has a floating label.
- return noLabelFloat ? -4 : 16;
+ return noLabelFloat ? -4 : 8;
+ },
+
+ /**
+ * Returns false if the element is required and does not have a selection,
+ * and true otherwise.
+ * @return {Boolean} true if `required` is false, or if `required` is true
+ * and the element has a valid selection.
+ */
+ _getValidity: function() {
+ return this.disabled || !this.required || (this.required && this.value);
}
});
})();
</script>
-
« no previous file with comments | « lib/src/paper-dialog-behavior/paper-dialog-common.css ('k') | lib/src/paper-dropdown-menu/test/paper-dropdown-menu.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698