Skip to content

Commit

Permalink
Merge pull request #1276 from carloslancha/issue-1275-sync-data
Browse files Browse the repository at this point in the history
Fixes #1275 - Sync data attributes in ClayComponent
  • Loading branch information
julien authored Oct 31, 2018
2 parents 9c1a553 + 2643914 commit a396d1c
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/clay-component/src/ClayComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ class ClayComponent extends Component {
rendered(...args) {
super.rendered(...args);

for (let dataKey in this.data) {
if (Object.prototype.hasOwnProperty.call(this.data, dataKey)) {
this.element.setAttribute(
'data-' + dataKey,
this.data[dataKey]
);
}
this._renderDataAttributes();
}

/**
* @inheritDoc
*/
syncData(newVal, prevVal) {
if (newVal != prevVal) {
this._renderDataAttributes();
}
}

Expand Down Expand Up @@ -121,6 +123,20 @@ class ClayComponent extends Component {
this.runListeners_(listeners, args, facade);
return true;
}

/**
* Places the data attributes in the dom.
*/
_renderDataAttributes() {
for (let dataKey in this.data) {
if (Object.prototype.hasOwnProperty.call(this.data, dataKey)) {
this.element.setAttribute(
'data-' + dataKey,
this.data[dataKey]
);
}
}
}
}

/**
Expand Down

0 comments on commit a396d1c

Please sign in to comment.