I am encountering some problems with a custom element created by me, called <little-game></little-game>.
This is <little-game></little-game> template code :
<template>
<a href="{{link}}">
<paper-material elevation="1">
<paper-ripple></paper-ripple>
<iron-image src="{{img_url}}"></iron-image>
<div id="description">{{name}}</div>
<div id="category">{{category}}</div>
</paper-material>
</a></template>
And the :host css of this element:
:host {
display: inline-block;
text-decoration: none;
z-index:1;
}
Those <little-game></little-game> elements are displayed in a page and inside this page i have a <paper-scroll-header-panel> and a <paper-toolbar>. The problem is when i scroll down and the .tall <paper-toolbar> gets smaller, i can click through the <paper-toolbar> on <little-game>/<paper-ripple> element.
<paper-ripple> css :
paper-ripple {
z-index:1;}
mainToolbar html :
<paper-toolbar id="mainToolbar" class="tall">
<paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
<span class="flex"></span>
<!-- Toolbar icons -->
<!--paper-icon-button icon="refresh"></paper-icon-button-->
<paper-icon-button icon="more-vert"></paper-icon-button>
<!-- Application name -->
<div class="middle middle-container center horizontal layout">
<div class="app-name">App title</div>
</div>
<!-- Application sub title -->
<div class="bottom bottom-container center horizontal layout">
<div class="bottom-title paper-font-subhead">App subtitle</div>
</div>
</paper-toolbar>
mainToolbar css :
#mainToolbar {
z-index:3;}
So the main problem is about that i can click the <little-game></little-game> element through the toolbar.
There is an image to understand what i am talking about in a better way:
I think you need to cancel the tap event from propagating through, try adding an on-tap event handler on the paper-toolbar e.g.
<paper-toolbar id="mainToolbar" class="tall" on-tap="{{cancelEvent}}">
then add the function to cancel it
cancelEvent: function(event) {
event.stopPropagation();
}
Related
Using the template from starter kit 2, is it possible to have the app drawer below the app-header? Right now the app drawer starts from the top of viewport and is columnized next to app-header.
I would like my app to be like google keep and google cloud console where the app header spans the entire width of the viewport and the app drawer begins underneath.
After reading the element catalog for app-layout, I did not see a offical api/attribute to set this. I've tried a few things but no success:
<app-drawer-layout fullbleed>
<!-- Drawer content -->
<app-header condenses reveals effects="waterfall">
<app-toolbar>
<paper-icon-button icon="menu" drawer-toggle></paper-icon-button>
<div main-title>My App</div>
</app-toolbar>
</app-header>
<app-drawer>
<app-toolbar>Menu</app-toolbar>
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="view1" href="/view1">View One</a>
<a name="view2" href="/view2">View Two</a>
<a name="view3" href="/view3">View Three</a>
</iron-selector>
</app-drawer>
Basically you need to use an app-drawer-layout inside an app-header-layout.
Here is a JSBin with the desired layout.
And the code itself:
<dom-module id="test-app">
<template>
<style>
:host {
display: block;
--app-primary-color: #3F51B5;
}
app-header {
background-color: var(--app-primary-color);
color: white;
}
app-drawer {
top: 64px;
--app-drawer-content-container: {
padding: 0px;
background-color: #eee;
};
}
</style>
<app-header-layout fullbleed>
<app-header fixed shadow>
<app-toolbar id="toolbar">
<paper-icon-button icon="menu" on-tap="_onTap"></paper-icon-button>
<div main-title>Stormwind</div>
</app-toolbar>
</app-header>
<app-drawer-layout>
<app-drawer id="drawer">
drawer content
</app-drawer>
<div>
main content
</div>
</app-drawer-layout>
</app-header-layout>
</template>
<script>
Polymer({
is: 'test-app',
properties: {
},
ready: function() {
},
attached: function() {
},
_onTap: function() {
this.$.drawer.toggle();
}
});
</script>
</dom-module>
NOTE
You need to manually handle the drawer button (the drawer-toggle property won't work).
Is there anything like drawer-toggle except that it doesn't toggle the menu? I want to add a similar attribute to paper-icon-button to show/hide the icon button based on whether the drawer is shown or not. I know I can get the boolean from app-drawer-layout.narrow, but my code is not exactly like the following and it's not easy to have an reference to <app-drawer-layout>. The following is just an example of providing the context of what I meant by drawer-toggle.
<app-drawer-layout>
<app-drawer>
drawer-content
</app-drawer>
<app-header-layout>
<app-header>
<app-toolbar>
<paper-icon-button icon="close" drawer-toggle></paper-icon-button>
<div main-title>App name</div>
</app-toolbar>
</app-header>
main content
</app-header-layout>
</app-drawer-layout>
You can bind a boolean property to the app-drawer-layout's narrow property and use this with an observer to show/hide the paper-icon-button. Example:
<dom-module id="test-app">
<template>
<style>
.hide {
display: none;
}
</style>
<app-drawer-layout fullbleed narrow="{{visible}}">
<app-drawer id="drawer">
drawer content
</app-drawer>
<app-header-layout>
<app-header>
<app-toolbar>
<paper-icon-button id="button" icon="menu" on-tap="_onTap"></paper-icon-button>
<div class="title" main-title>App name</div>
</app-toolbar>
</app-header>
<div>
main content
</div>
</app-header-layout>
</app-drawer-layout>
</template>
<script>
Polymer({
is: 'test-app',
properties: {
visible: {
type: Boolean,
observer: '_visibleChanged'
}
},
_onTap: function() {
console.log(this.visible);
this.$.drawer.toggle();
},
_visibleChanged: function(value) {
this.toggleClass('hide', !value, this.$.button);
}
});
</script>
</dom-module>
Note that now you need to manually handle the drawer toggle (_onTap function).
I'm using Polymer 1.0 Starter Kit. I'm trying to change toolbar's background and color when changing routes.
<paper-scroll-header-panel main id="headerPanelMain" condenses keep-condensed-header
header-height="256" condensed-header-height="100">
<paper-toolbar>
<paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
<span class="space"></span>
<!-- Toolbar icons -->
<nt-toolbar-icons></nt-toolbar-icons>
<!-- Application name -->
<div class="middle middle-container">
<div class="app-name">[[route.title]]</div>
</div>
<!-- Application sub title -->
<div class="bottom bottom-container">
<div class="bottom-title">[[route.subline]]</div>
</div>
</paper-toolbar>
<div style="height: 1400px;">
<iron-pages attr-for-selected="data-route" selected="{{route.name}}">
<section data-route="home">
{{route.title}} /
</section>
<section data-route="users">
users {{route.params.type}}
</section>
</iron-pages>
</div>
</paper-scroll-header-panel>
</paper-drawer-panel>
Route is defined in elements/routing.html
page('/', function() {
app.route = {
name: 'home',
title: 'noTos+',
subline: ''
}
});
In my shared-styles.html my toolbar is defined this way:
paper-scroll-header-panel#headerPanelMain {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: var(--paper-grey-200, #eee);
/* background for toolbar when it is at its full size */
--paper-scroll-header-panel-full-header: {
background-image: url(../images/headers/bg4.jpg);
}
/* background for toolbar when it is condensed */
--paper-scroll-header-panel-condensed-header: {
background-color: var(--paper-light-blue-600);
}
}
But now I want this color/background-scheme to be changed when the route is changed.
I've tried adding data-route$="[[route.name]]" to paper-scroll-header-panel.
Then I've changed shared-styles.html with the [data-route="home"] selector:
paper-scroll-header-panel#headerPanelMain[data-route="home"] {
--paper-scroll-header-panel-full-header: {
background-image: url(../images/headers/bg3.jpg); //BG CHANGES HERE
}
}
But this doesn't work.
Any other ideas?
Custom styles are only applied at creation time. If you have dynamic changes like you do here, you need to call updateStyles on you custom element or Polymer.updateStyles for a global update. In your case, you would do that when the route changes. You can find more info in the documentation.
you can do the following.
<paper-toolbar id="mainToolbar" class="tall" style$={{computedStyleHandler(color)}}>
computedStyleHandler: function(color){
return 'background-color:' + color + ';'
}
I would like the paper-ripple effect to fill<div class='title bottom'> also. Any ideas on how to make it do that?
<body unresolved>
<paper-header-panel shadow="true"
mode="waterfall-tall"
class="fit">
<paper-toolbar>
<paper-ripple fit></paper-ripple>
<div class='title'></div>
<paper-tabs noink="true" selected="0">
<!-- only HOME gets route. Others will but down below -->
<paper-tab class="route" onclick="page('/')">
HOME
</paper-tab>
<paper-tab onclick="page('/resume')">
RESUME
</paper-tab>
<paper-tab>
CONTACT
</paper-tab>
</paper-tabs>
<div class='title bottom'>
<h1 id="name-title">Foo<p> bar<p></h1>
</div>
</paper-toolbar>
UPDATE...plunker example condenses paper-header-panel in non waterfall mode:
<paper-header-panel
mode="waterfall-tall"
class="fit">
<div>
<paper-toolbar>
<paper-tabs>
<!-- only HOME gets route. Others will but down below -->
<paper-tab class="route" onclick="page('/')">
HOME
</paper-tab>
</paper-tabs>
</paper-toolbar>
<paper-ripple></paper-ripple>
</div>
</paper-header-panel>
paper-toolbar has three vertically stacked divs. So having a paper-ripple that takes the whole space is not an option here. What you can do is to wrap the paper-toolbar with a parent div and have the paper-ripple sit at the same level as the paper-toolbar.
Note that this parent div needs to have a paper-header class so that the paper-header-panel knows it's the header and will assign proper styling to it. Also, to constraint the paper-ripple, this parent div needs to be relative position.
The last change you need to make is to manually give the paper-toolbar a tall class since it's no longer the paper-header-panel's direct children.
<paper-header-panel mode="waterfall-tall" class="fit">
<div class="paper-header relative">
<paper-toolbar class="tall">
<div class="title"></div>
<paper-tabs noink selected="0">
<paper-tab class="route" onclick="page('/')">HOME</paper-tab>
<paper-tab onclick="page('/resume')">RESUME</paper-tab>
<paper-tab>CONTACT</paper-tab>
</paper-tabs>
<div class="title bottom">
<h1 id="name-title">Foo<p> bar<p></h1>
</div>
</paper-toolbar>
<paper-ripple></paper-ripple>
</div>
</paper-header-panel>
Check out this plunker.
We currently have an paper tab view with 3 tabs, each tab loads its own iron page. Inside the iron page we pull a list of elements using an API. The iron list successfully loads the api results but we can only view the first few elements.
The other elements are hidden as we are unable to scroll. How do we make the list scrollable? as the list view grows in size. The list is dynamically loaded when a particular tab is selected.
<paper-drawer-panel id="paperDrawerPanel">
<!-- Drawer Scroll Header Panel -->
<paper-scroll-header-panel drawer fixed>
<!-- Drawer Toolbar -->
<paper-toolbar id="drawerToolbar">
<span class="paper-font-title"><div class="logo"></div></span>
</paper-toolbar>
<!-- Drawer Content -->
<paper-menu class="list" attr-for-selected="data-route" selected="[[route]]">
<a data-route="home" href="/" >
<iron-icon icon="home"></iron-icon>
<span>Home</span>
</a>
<a data-route="todays-sminq" href="/todays-sminq" on-click="onDataRouteClick">
<iron-icon icon="info"></iron-icon>
<span>Today's sminq</span>
</a>
<a data-route="upcoming-sminq" href="/upcoming-sminq" on-click="onDataRouteClick">
<iron-icon icon="mail"></iron-icon>
<span>Upcoming sminq</span>
</a>
<a on-click="logOut">
<iron-icon icon="user"></iron-icon>
<span>Log Out</span>
</a>
</paper-menu>
</paper-scroll-header-panel>
<!-- Main Area -->
<paper-header-panel main condenses keep-condensed-header>
<!-- Main Toolbar -->
<paper-toolbar id="mainToolbar" class="small">
<paper-icon-button id="paperToggle" icon="menu" paper-drawer-toggle></paper-icon-button>
<span class="flex"></span>
<!-- Toolbar icons -->
<paper-icon-button icon="refresh"></paper-icon-button>
<paper-icon-button icon="search"></paper-icon-button>
<!-- Application name -->
<div class="middle middle-container center horizontal layout">
<div class="app-name">Sminq</div>
</div>
<!-- Application sub title -->
<!--<div class="bottom bottom-container center horizontal layout">-->
<!--<div class="bottom-title paper-font-subhead">waiting is now fun</div>-->
<!--</div>-->
</paper-toolbar>
<!-- Main Content -->
<div class="content">
<iron-pages attr-for-selected="data-route" selected="{{route}}">
<section data-route="home" >
<live-sminq ></live-sminq>
<!--paper-material elevation="1">
</paper-material>
<paper-material elevation="1">
</paper-material>
<paper-material elevation="1" class="paper-font-body2">
</paper-material-->
</section>
<section data-route="todays-sminq" id="sectiontodays" >
<todays-sminq></todays-sminq>
<!--paper-material elevation="1">
</paper-material-->
</section>
<section data-route="sminq-info">
<sminq-single
token_id ="{{params.id}}" token_number="{{params.no}}" user_name="{{params.name}}"
status_type="{{params.status}}"
user_mobile ="{{params.mobile}}"
queue_id ="{{params.queueId}}"
sminq_type="{{params.sminqType}}"
joinDate="{{params.date}}"
>
</sminq-single>
</section>
<section data-route="live-tokens"class="layout vertical fit">
<live-tokens
queue_id="{{params.id}}" user_name="{{params.name}}">
</live-tokens>
</section>
<section data-route="upcoming-sminq">
<upcoming-sminq>
</upcoming-sminq>
</section>
<section data-route="not-found">
<paper-material elevation="1">
<h2 class="page-title">Page Not Found</h2>
<p></p>
</paper-material>
</section>
</iron-pages>
</div>
</paper-header-panel>
</paper-drawer-panel>
This is our main index.html we have created separate module which loads the tabs and the list view
The code for this module is attached below
<iron-ajax
id="list"
headers='{"Authorization": "xxxx","X-Vertical-Type": "xxx" }'
content-type="application/json"
url=""
handle-as="json"
method="GET"
on-error="handleErr"
debounce-duration="300"
last-response="{{ liveQueues }}"
on-response="ajaxResponse">
</iron-ajax>
<!--<template auto is="dom-if" if="{{loading}}"style="width:100%;">-->
<!--<paper-progress value="10" indeterminate="true" ></paper-progress>-->
<!--</template>-->
<div></div>
<span style="display:none;">[[selected]]</span>
<paper-spinner id="spinner" alt="Loading tokens numbers" ></paper-spinner>
<paper-tabs id="scrollableTabs" selected={{selected}} scrollable >
<template is="dom-repeat" items="[[liveQueues]]" as="queue" >
<paper-tab on-click="listLiveTokens" >[[queue.queueName]]</paper-tab>
</template>
</paper-tabs>
<iron-pages selected="{{selected}}">
<template is="dom-repeat" items="[[liveQueues]]" as="queue" >
<paper-material elevation="1">
<iron-list items="[[queueTokens]]" as="token">
<template>
<div>
<div class="item" tabindex="0">
<span class="avatar" >[[token.tokenNumber]]</span>
<a href$="{{_getDetailsLink(token.tokenId,token.tokenNumber,token.userName,token.statusType,token.userMobile,token.joinDate)}}">
<div class="pad">
<div class="primary">[[token.userName]]</div>
<div class="secondary">[[token.userMobile]]</div>
<div class="secondary dim">[[token.notes]]</div>
<div class="secondary dim">[[token.joinTime]]</div>
</div>
</a>
<iron-icon icon$="[[iconForItem(sminq)]]"></iron-icon>
</div>
</div>
</template>
</iron-list>
</paper-material>
</template>
</iron-pages>
<iron-ajax
id="tokens"
headers='{"Authorization": "xxx","X-Vertical-Type": "xxxx" }'
content-type="application/json"
url=""
handle-as="json"
method="GET"
on-error="tokenError"
debounce-duration="300"
last-response="{{ queueTokens }}"
on-response="tokenResponse">
</iron-ajax>
<template is="dom-if" if="{{isQueueId}}">
<sminq-add queue_id="{{queueId}}"></sminq-add>
</template>
You can implement IronResizableBehavior to resize your list when you switch tabs (note: it should work by default though):
iron-list lays out the items when it receives a notification via the resize event. This event is fired by any element that implements IronResizableBehavior.
By default, elements such as iron-pages, paper-tabs or paper-dialog will trigger this event automatically. If you hide the list manually (e.g. you use display: none) you might want to implement IronResizableBehavior or fire this event manually right after the list became visible again. e.g.
document.querySelector('iron-list').fire('resize');