我在下面的代码段中实现了一个多选下拉菜单。它似乎工作正常。但是,每次选择项目时,菜单都会关闭。我希望菜单保持打开状态,直到用户点击“完成”按钮。
奇怪的是,如果取消选择某个项目,菜单会保持打开状态,但如果我选择了某个项目,则会关闭。
html, body {
height: 100%;
}
body {
overflow: hidden;
margin: 0;
font-family: RobotoDraft, 'Helvetica Neue', Helvetica, Arial;
-webkit-tap-highlight-color: rgba(0,0,0,0);
-webkit-touch-callout: none;
}
paper-button {
margin: 20px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Polymer</title>
<base href="http://polygit.org/components/">
<script src="webcomponentsjs/webcomponents-lite.min.js"></script>
<link rel="import" href="paper-item/paper-item.html">
<link rel="import" href="paper-dropdown-menu/paper-dropdown-menu.html">
<link rel="import" href="paper-menu/paper-menu.html">
</head>
<body>
<foo-drop ></foo-drop>
<dom-module id="foo-drop">
<template>
<paper-dropdown-menu label="Your favourite pastry">
<paper-menu id="myMenu" class="dropdown-content" multi>
<paper-item>Croissant</paper-item>
<paper-item>Donut</paper-item>
<paper-item>Financier</paper-item>
<paper-item>Madeleine</paper-item>
</paper-menu>
</paper-dropdown-menu>
</template>
<script>
Polymer({
is: "foo-drop",
ready: function() {
window.addEventListener('WebComponentsReady', function() {
var menu = document.querySelector("#myMenu");
menu.addEventListener("iron-select", function(e, detail){
console.log(menu.selected);
console.log(menu.selectedItems.length);
for (var i = 0; i < menu.selectedItems.length; i++)
console.log(menu.selectedItems[i].value);
});
});
}
});
</script>
</dom-module>
</body>
</html>
答案 0 :(得分:2)
paper-dropdown-menu
中关闭/打开菜单的控件使用paper-menu-button
。
https://github.com/PolymerElements/paper-dropdown-menu/blob/master/paper-dropdown-menu.html#L150
规范声明将ignoreSelect
设置为true
。
https://elements.polymer-project.org/elements/paper-menu-button
这有一个错误 https://github.com/PolymerElements/paper-menu-button/issues/58
但也许适用于您的环境(至少在Chrome和Firefox上有效)。检查ignore-select
是否在&#34;纸质菜单中使用多项选择&#34;
https://elements.polymer-project.org/elements/paper-menu-button?view=demo:demo/index.html&active=paper-menu-button
如果有,则从paper-dropdown-menu
获取基础paper-menu-button
并设置ignoreSelect = true
;
使用
<paper-dropdown-menu id="id_my-paper-dropdown-menu">
集合ignoreSelect
应该设置为类似的东西(我主要在Dart框架中工作):
this.$.id_my-paper-dropdown-menu.$.menuButton.ignoreSelect = true;