Comments (8)
Hi @zoechi, it is not a typo since the element is a <button>
, and we execute the document.querySelector('#toast0').open()
on the event onclick
from paper-toast.
@valdrinkoshi I see. Sorry for the noise.
I'm using Polymer from Dart and here it's not very common to use dom-bind
.
I ported all element demos to Dart recently and there I replaced all dom-bind
with an app-element
. I found it weird that all examples assume the elements will be used on the body tag, not within the template of another component and such JS is used instead of Polymer binding.
Just saying, not action required/expected ;-)
from paper-toast.
We do it mainly to be concise in our examples, without requiring too much Polymer notation or other elements' knowledge. In a real application that code would be more verbose, something like this:
<!-- app-element.html -->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../paper-toast/paper-toast.html">
<link rel="import" href="../paper-button/paper-button.html">
<dom-module id="app-element">
<template>
<paper-toast id="toast0" text="Welcome back!"></paper-toast>
<paper-button on-click="openToast">Login</paper-button>
</template>
</dom-module>
<script>
Polymer({
is: 'app-element',
openToast: function() {
this.$.toast0.open();
}
});
</script>
from paper-toast.
That's how I translated it :)
Just my opinion - this way the demo source is better from an educational POV.
from paper-toast.
you're right, also looking at other docs (e.g. iron-collapse
https://github.com/PolymerElements/iron-collapse) we do use Polymer notation. Will re-open and update the docs!
from paper-toast.
For something as simple as this, I don't think it makes sense to create a full element. We also want folks to know how to use elements/DOM outside of Polymer features. A 2-line example is much easier to grok than a list of imports, element, and polymer features. My $0.02.
from paper-toast.
@ebidel, would something like
<paper-button on-click="openToast">Open toast</paper-button>
<paper-toast id="toast" text="Welcome back!"></paper-toast>
...
openToast: function() {
this.$.toast.open();
}
be better than just
<button onclick="document.querySelector('#toast').open()">Open toast</button>
<paper-toast id="toast" text="Welcome back!"></paper-toast>
The drawback of the first though is that it won't work out-of-the-box if you copy-paste it, while the second would just work
from paper-toast.
The first seems fine. I don't think the docs example code needs to be copy-and pasteable. We have the fuller demo examples and doc site for that :)
from paper-toast.
Related Issues (20)
- Hide then show toast HOT 5
- open() close() etc. methods HOT 1
- Allow custom styling for paper-toast HOT 2
- Toast remaining as invisible barrier in Chrome
- override resetFit rather than center
- paper-toast's alignment abilities is a lie. HOT 5
- The `paper-toast` element is hidden from drawer content on iPad with Safari HOT 4
- <paper-toast> is partially hidden by app-drawer HOT 12
- Pattern to create multiple toast HOT 2
- , HOT 2
- paper-toast doesn't support center alignment HOT 7
- paper-toast does not scroll correctly when fitInto is set. HOT 1
- Callback when toast closes HOT 1
- Button within toast falls out of alignment upon receiving keyboard focus. HOT 3
- Align button HOT 1
- noCancelOnOutsideClick is false but still not closes the toast on clicking on 'paper-tabs' area HOT 2
- this element doesn't appear in any collection webcomponents.org HOT 4
- Toast fitInto/fit-bottom not working correctly. HOT 5
- calling hide() function on paper-toast loses focus on paper-input inside paper-dialog HOT 5
- On-tap doesn't work on mobile HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from paper-toast.