Skip to content

Commit

Permalink
Trigger checkble click event first then change event (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizniz187 committed Sep 12, 2021
1 parent 55d795b commit 6a4560a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
12 changes: 0 additions & 12 deletions wc/WComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class WComponent extends HTMLElement{
constructor(){
super();
this.createGettersAndSetters();
this.bindProps();
this.attachShadow({ mode: 'open' });
this.setStylesheet(this.stylesheet);
this.componentWillRender();
Expand All @@ -27,17 +26,6 @@ class WComponent extends HTMLElement{
componentWillRender() {}
componentDidRender() {}

/**
* Set all properties from all observed attributes.
*/
bindProps() {
if(!Array.isArray(this.constructor.observedAttributes)) {
return;
}
this.constructor.observedAttributes.forEach(attr => {
this[attr.name] = this.getAttribute(attr.name);
});
}
/**
* Dynamically create getters & setters for property-attribute sync
* by parsing class field attribute object.
Expand Down
1 change: 1 addition & 0 deletions wc/components/checkable/Checkable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const stylesheet=`
`;

class Checkable extends WComponent{

static attributes = {
checked: {
name: 'checked', defaultValue: false,
Expand Down
4 changes: 3 additions & 1 deletion wc/components/checkable/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ const stylesheet=`
`;

class Checkbox extends Checkable{

constructor() {
super();
this.bindEvents();
}

clickHandler = e => {
this.dispatchEvent(this.events.click);
if(!this.disabled) {
this.checked = !this.checked;
}
e.stopPropagation();
};


}
Checkbox.prototype.stylesheet += stylesheet;
Checkbox.prototype.type = 'checkbox';
Expand Down
4 changes: 4 additions & 0 deletions wc/components/checkable/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ const stylesheet=`
}
`;
class Radio extends Checkable{

constructor() {
super();
this.bindEvents();
}

clickHandler = e => {
this.dispatchEvent(this.events.click);
if(!this.disabled && !this.checked) {
this.checked = !this.checked;
}
e.stopPropagation();
};

}
Radio.prototype.stylesheet += stylesheet;
Radio.prototype.type = 'radio';
Expand Down

0 comments on commit 6a4560a

Please sign in to comment.