Comments (11)
Description about the event added by 63af3b5
from material-design-inspired-color-picker.
@BennyAlex , Event delegation is good practice https://javascript.info/event-delegation
One eventlinstener vs two. example -
document.addEventListener('change', function(e) {
var target = e.target;
switch(target.id) {
case 'picker':
// some code...
break;
case 'picker1':
// some code...
break;
default:
}
});
from material-design-inspired-color-picker.
Picker need listener type "change" to get variable in event object.
Why i didn't find this information in docs?
I had to pick the demo:)
var picker = document.getElementById('picker');
function listenerEvent (event) {
console.log(event);
var color = event.detail[0];
console.log('Selected Color:', color);
picker.value = color;
}
picker.addEventListener('change', listenerEvent, false);
from material-design-inspired-color-picker.
And, please, remove stopPropagation from code :)
from material-design-inspired-color-picker.
@rasy-js Hello, thank you for your feedback :D
Can you explain me what you mean by "remove stopPropagation"?
I will add the information about the change event to the docs ;)
from material-design-inspired-color-picker.
@BennyAlex , now event is not bubbling, if register event on document. And then to click the picker elements.
I had removed Event.stopPropagation() from code, and event bubbled.
from material-design-inspired-color-picker.
@rasy-js
Hey, this plugin is created from vue and vue-custom-element and then transformed with webpack to a module.
The dist/md-color-picker.js file is gererated automatically from the source files.
I simply call this.$emit('change', color.value)
. Maybe there is a setting to remove the geratoin of Event.stopPropagation()
but maybe this is a default behaviour which can't be changed
from material-design-inspired-color-picker.
I planning to release the color picker as a basic javascript module without vue and vue-custom-element, which would reduce the size of the picker drastically, then Event.stopPropagation()
would be removed, too
from material-design-inspired-color-picker.
It's very good idea, then can to close issue.
from material-design-inspired-color-picker.
@rasy-js
But as far as I know, register an event on the document isn't a good idea. For example, when there is another element which also sends an 'change' event, this would trigger the eventlistener, too. Or if you want to use 2 color pickers on the same page, you dont know which one sent the event.
from material-design-inspired-color-picker.
It is better to get the element (e.g. by ID) and then register the event directly on it.
from material-design-inspired-color-picker.
Related Issues (2)
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 material-design-inspired-color-picker.