My Expectation here would be that 'Option 1' would be selected by default once the page loads. This is not what is happening. Instead it shows the label, not the selected option based on the paper-item value attribute.
<paper-dropdown-menu name="dropdown" label="Dropdown" selected='1' valueattr='value'>
<paper-dropdown class="dropdown">
<core-menu class="menu">
<paper-item value="1">Option 1</paper-item>
<paper-item value="2">Option 2</paper-item>
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
The selected
attribute can be used in conjunction with an element that extends <core-selector>
to control what's selected. Out of the set of elements you're using in your example, <core-menu>
is the one that extends <core-selector>
, so you need to set the selected
attribute on that.
Here's a modified example that works as expected:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Polymer Demo</title>
</head>
<body>
<script src="//www.polymer-project.org/webcomponents.js"></script>
<link rel="import" href="//www.polymer-project.org/components/paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="//www.polymer-project.org/components/paper-dropdown/paper-dropdown.html">
<link rel="import" href="//www.polymer-project.org/components/core-menu/core-menu.html">
<link rel="import" href="//www.polymer-project.org/components/paper-item/paper-item.html">
<h1>Dropdown Menu</h1>
<paper-dropdown-menu label="Select an item">
<paper-dropdown class="dropdown">
<core-menu class="menu" selected="1" valueattr="value">
<paper-item value="1">Option 1</paper-item>
<paper-item value="2">Option 2</paper-item>
</core-menu>
</paper-dropdown>
</paper-dropdown-menu>
</body>
</html>
Note that you need to also set valueattr="value"
on the <core-menu>
to indicate that each of the <core-menu>
children have value
attributes set that correspond to what will be passed in to the select
attribute. (The default is valueattr="name"
which would require that you set name
attributes on each of the <paper-item>
s.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With