Reputation: 2247
I'm trying to create a page with core-submenu
(and therefore also "subpages" (not a real component)). But as I've seen around the web there's a "problem" with this, since a press on a core-submenu
item will trigger the selected
event even though naturally one only want it triggered when a child element is pressed on.
I found this link which explain a method to achieve what I want, but this approach relies on ids on all the pages and core-submenu
childs. I have no need to "loop"-generate my menu. By not using core-submenu
everything is working without even the slightest javascript-code.
Is there some built-in support for core-pages and core-submenu that can be used? In otherwords: A way that does not require any (or minimal) use of javascript?
.
. //some code here
.
<core-menu theme="core-light-theme" selected="{{selected}}" selectedItem={{item}}>
<core-submenu icon="settings" label="Favorites">
<core-item icon="https" label="Hello"></core-item>
<core-item icon="https" label="World"></core-item>
</core-submenu>
</core-menu>
.
. //some code here
.
<core-animated-pages transitions="cross-fade" selected="{{selected}}">
<section id="page-1">
<div cross-fade>Hello content</div>
</section>
<section id="page-2">
<div cross-fade>World content</div>
</section>
</core-animated-pages>
.
. //some code here
.
Thank you!
Upvotes: 0
Views: 219
Reputation: 341
try to use valueattr for ex:
<core-menu theme="core-light-theme">
<core-submenu icon="settings" label="Favorites" valueattr="number" selected="{{number}}">
<core-item icon="https" label="Hello" number="0"></core-item>
<core-item icon="https" label="World" number="1"></core-item>
</core-submenu>
<core-submenu icon="settings" label="Favorites2" valueattr="number" selected="{{number}}">
<core-item icon="https" label="Hello2" number="2"></core-item>
<core-item icon="https" label="World2" number="3"></core-item>
</core-submenu>
</core-menu>
<core-animated-pages transitions="cross-fade" selected="{{number}}">
<section id="page-1">
<div cross-fade>Hello content - {{number}}</div>
</section>
<section id="page-2">
<div cross-fade>World content - {{number}}</div>
</section>
<section id="page-3">
<div cross-fade>Hello content - {{number}}</div>
</section>
<section id="page-4">
<div cross-fade>World content - {{number}}</div>
</section>
</core-animated-pages>
Upvotes: 2
Reputation: 388
Well, you could dump the idea of having a "shared selected" and instead have something that respond on "core-select" event.
This will work just fine.
<template is='auto-binding'>
<core-scaffold>
<core-header-panel navigation flex>
<core-toolbar>Menu</core-toolbar>
<core-menu on-core-select='{{navFunc}}'>
<core-item label='page1'></core-item>
<core-submenu label='something' type='submenu'>
<core-item label='page2'></core-item>
<core-item label='page3'></core-item>
<core-submenu label='super submenu' type='submenu'>
<core-item label='page4'></core-item>
<core-item label='page5'></core-item>
</core-submenu>
</core-submenu>
<core-submenu label='more here' type='submenu'>
<core-item label='page6'></core-item>
<core-item label='page7'></core-item>
</core-submenu>
</core-menu>
</core-header-panel>
<core-animated-pages selected='{{myselection}}' valueattr='label'>
<section label='page1'>Page1</section>
<section label='page2'>Page2</section>
<section label='page3'>Page3</section>
<section label='page4'>Page4</section>
<section label='page5'>Page5</section>
<section label='page6'>Page6</section>
<section label='page7'>Page7</section>
</core-animated-pages>
</core-scaffold>
</template>
<script>
var template = document.querySelector('template[is="auto-binding"]');
template.navFunc = function(e, detail){
if (detail.item.getAttribute('type') !== 'submenu' && detail.isSelected == true) {
template.myselection = detail.item.getAttribute('label');
}
}
</script>
Upvotes: 1