I'm having some trouble migrating to Polymer 1.0
My main problem is that the classes "style-scope" and "my-element" are being applied to every child node in the element. This is not a problem when using something like this:
<paper-dialog modal class="vertical layout">
<div class="top">
<div class="green">{{format(inputtext)}}</div>
It just changes their classes to "top style-scope my-element" and "green style-scope my-element" respectively and everything works ok.
But right now on Polymer 1.0 I can't bind a classname to a property, so I have to compute it with something like this:
<template is="dom-repeat" items="{{ item-list }}" as="item">
<span class="{{setitemclass(item)}}" on-click="itemClicked" role="button" >{{item}}</span>
</template>
setitemclass: function (item) {
return 'itnumb' + item;
}
As the element is created every span created goes through the setitemclass function and it returns what it should (something like 'itnumb1', 'itnumb2' and so on), but when it finishes, the class appears as "style-scope my-element" for every span, with no sigh of the 'itnumb#' bit anywhere.
I just don't know how to approach this, since binding has changed quite a bit in my eyes.
Thanks!
In order to bind to an attribute that does not match to a respective JS property of that element (e.g. class, href, data-*), you should use $= rather than plain =.
<span class$="{{setitemclass(item)}}" on-click="itemClicked" role="button">{{item}}</span>
Source: https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#attribute-binding
Related
While updating my polymer project from 1.x to 2.0 I encountered this problem
I am wrapping one of my custom elements in dom-repeat like this
Host
<dom-repeat items="{{customer.hubs}}" as="item">
<template>
<paper-card elevation="2" class="hubCard">
<div style="font-size: 25px;font-weight: bold;line-height: 48px">HUB [[printIndex(customer.hubs,index)]]</div>
<hub-info hub="{{item}}" isloading="{{isloading}}" refresh-customer="[[refreshCustomer]]"/>
</paper-card>
</template>
</dom-repeat>
part of the code of custom element is like below
Custom element
<div class="blueButton" id="debugTab" style="padding-top: 10px">
<dom-if if="{{displayDebugger}}">
<template>
<div class="headButton" on-click="toggleDebugger" id="debuggerTab">
<span>Debugger</span>
<span style="position: absolute;right: 2%">
<!--<i id="downArrow4" class="material-icons fa-arrow-down">keyboard_arrow_down</i>-->
<iron-icon id="downArrow4" icon="icons:arrow-drop-down"></iron-icon>
</span>
</div>
</template>
</dom-if>
<iron-collapse id="collapseDebugger" >
<hub-debugger hub-id="{{hub.hubId}}" isloading="{{isloading}}"></hub-debugger>
</iron-collapse>
</div>
Problem
First i tried to access iron-collapse as
this.$.collapseDebugger but i couldn't ,as i thought the custom elemrnt hub-info is inside dom-repeat i used this.shadowRoot.querySelector('#collapseDebugger') and accessed it.
Again i tried to access iron-icon (which is again dynamically created inside dom-if) as this.shadowRoot.querySelector('#downArrow4') but i am unable to access it.
How to access a dynamic node inside dynamic element?
What if there is nesting of dynamic creations?
The this.shadowRoot.querySelector(selector) syntax should work.
Is the conditional template actually rendered? Do you import polymer/lib/elements/dom-if.html in your custom element? This is needed, if you otherwise only import polymer/polymer-element.html.
I am using something like this:
<neon-animated-pages class="flex" selected="{{route}}" attr-for-selected="data-route" on-iron-select="_pageChanged" on-neon-animation-finish="_onNeonAnimationFinish">
<sys-neonpage1 data-route="home" id="page1" class="fit"></sys-neonpage1>
<sys-neonpage2 data-route="users" id="page2" class="fit"></sys-neonpage2>
<sys-elemento data-route="contact" id="page3" class="fit"></sys-elemento>
</neon-animated-pages>
That works fine, with the animations inside >sys-neonpage1...> But inside that element I have other elements which have some animations, what i want to do is that the animation of the element inside also run, but in this case it doesnt work, only the animations of works.
for exmaple inside I have something like this:
dom-module id="sys-neonpage1">
<template>
<sys-elemento class="prueba"></sys-elemento>
</template>
And the element has his own animations that never started if i use it inside ...
is that posible?, thanks a lot.
What you want to do is actually built-in the neon-animated-pages component: Running animations encapsulated in children nodes
In general, i recommend you read the whole "using neon-animations" guide as it is well written.
Our team is building our first polymer all in one page app and we kind of have to reverse engineer a neglected component of the project. We need to set the title for the title bar in the core-scaffolding. This is easy on simple pages by using JS, however some pages have conditional templates that show content and each require their own titles.
eg
<core-scaffolding>
<div id="title">Dynamic Title goes here</div>
<core-animated-pages transitions="cross-fade">
<section>
<div cross-fade>
<my-element>
<template if="{{condition1}}"></template>
Content 1
</template>
<template if="{{condition2}}"></template>
Content 2
</template>
<template if="{{condition3}}"></template>
Content 3
</template>
</my-element>
</div>
</section>
<section>
<div cross-fade></div>
</section>
</core-animated-pages>
I was going to add an attribute on the template elements to be able to pass a title value, however I don't know how to use JS to find out which template is the one that is conditionally rendered (active). I can't seem to find any documentation on this. Also I want to build something reusable (not with IDs) that can be used globally on any page.
Can anyone provide any suggestions?
Cheers,
david
i don't think i would use conditional template for this. if that condition changes a lot the content of the template will be added and removed from the dom every time it is changed. i think it would be better to use the hidden attribute or use databinding to change the text dynamically.
hidden attribute
<span hidden?="{{!condition1}}">Content 1</span>
<span hidden?="{{!condition2}}">Content 2</span>
<span hidden?="{{!condition2}}">Content 3</span>
databinding
<span>{{content}}</span>
then you can change the databind in javascript like normal.
if (condition1) {
this.content = 'Content 1';
}
I am working on migrating to Polymer 1.0
Here is my template:
<template>
<div class="scroll">
<div class="content">
<content></content>
</div>
<div class="bar barY"></div>
</div>
</template>
The content gets filled with text in the main html file.
I need to get the scroll height of this div. I used to do:
height = $(this.shadowRoot).find('.content')[0].scrollHeight;
But this isn't working anymore:
Uncaught TypeError: Cannot read property 'scrollHeight' of undefined
I tried adding an id to the div, and selecting it like so:
height = this.$.content.scrollHeight;
But this is giving me a value of 0, even though there is lots of text in the content.
I am calling this code from the ready function.
Am I selecting the element correctly?
<content> does not actually contain the component's contents, rather it provides an insertion point for those contents, which will be siblings to the <content> element. To get the elements which are inserted for a given <content> node, you can use the following:
var content = Polymer.dom(this.root).querySelector('content');
var distributed = Polymer.dom(content).getDistributedNodes()
Documentation for the above can be found at https://www.polymer-project.org/1.0/docs/devguide/local-dom.html#dom-api-examples along with a more complete example.
I should have specified that this is a polymer question and not native HTML.
I have a template like this
<template>
<a href="{{ href }}">
<content></content>
</a>
</template>
When I hover over the custom element my cursor iscursor:text and not cursor:pointer, this is an easy fix to apply cursor pointer, but I feel as if those kind of properties should be inherited. Is there any way to apply the content and inherit the a properties properly?
Example on jsfiddle here
Update: 1
An even bigger issue with this is that you can't right-click and select copy-link either.
Update: 2
I kind of think I get it now, <content> isn't being passed a height or width, so the outer most element (the custom one) is height 0, width 0. So the anchor has no room to expand. Hence the cursor isn't switching.
tried, no luck
::content * {
width:inherit;
height:inherit;
}
Update 3
This kinda worked.
I had to give the anchor a id=anchor and use jQuery.
$(this.$.anchor).append($(this).html());
This won't import font-awesome icons for some reason, where does.
Perhaps it's because it's not importing over the styles when I grab the HTML?
There's no error in the console either.
I dropped the to font-awesome within the polymer template and it worked, which is kind of crappy. Need a better solution.
This is a bug with Chrome's current implementation of Shadow DOM that will be fixed in Chrome 37.
You have nothing to make a link out of; you're "linkifying" an empty block.
If you give <content> some innards, you'll see the inherited style:
<template>
<a href="{{ href }}">
<content> Here is a link. </content>
</a>
</template>
Example Fiddle
I have no idea how you're actually using this element, but http://jsbin.com/qaqigizajuvi/1/edit is a simple example of how to make at least what I think you're trying to achieve, work.
If you're using {{ name }} macros, you'll need to declare attributes for each name that you use. There's also no point in a <content> block if you just want a linktext: use another attribute macro in your definition:
<polymer-element name="monkey-test" attributes="href label" noscript>
<template>
{{ label }}
</template>
</polymer-element>
and then instantiate it as either:
<monkey-test href="http://example.org" label="tadah"></monkey-test>
or set up a <monkey-test> element and then set its href and label attributes via JavaScript using e.href=... and e.label=... or e.setAttribute(name, value)
note that the noscript attribute is used here because there's no explicit script block with a new Polymer('monkey-test', { ... }) call. If we want a more complex element, we can't get away with noscript.