Skip to content

Commit

Permalink
QmlWeb.Dom/DomElement: support setting attrs and style
Browse files Browse the repository at this point in the history
Example:

```
import QtQuick 2.0
import QmlWeb.Dom 1.0

DomElement {
  width: 100
  height: 200
  attrs.id: 'myElement'
  style.background: 'green'
 }
```

This works only on DomElement elements (from QmlWeb.Dom) module which
contains DOM-specific components and is not interoperable with Qt QML.

It is, however, possible to at least partially mock QmlWeb.Dom behavior
with QtQuick QML, but that's not in scope.
  • Loading branch information
ChALkeR committed May 3, 2018
1 parent cae3cf1 commit 09b9a55
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/modules/QmlWeb.Dom/DomElement.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
// eslint-disable-next-line no-undef
class QmlWeb_Dom_DomElement extends QtQuick_Item {
static properties = {
attrs: { type: "var", initialValue: {} },
style: { type: "var", initialValue: {} },
tagName: { type: "string", initialValue: "div" }
};

constructor(meta) {
meta.tagName = meta.object.tagName;
super(meta);

// TODO: support properties, styles, perhaps changing the tagName
for (const key in meta.object.attrs) {
if (!meta.object.attrs.hasOwnProperty(key)) continue;
this.dom[key] = meta.object.attrs[key];
}
for (const key in meta.object.style) {
if (!meta.object.style.hasOwnProperty(key)) continue;
this.dom.style[key] = meta.object.style[key];
}
}
}

0 comments on commit 09b9a55

Please sign in to comment.