diff --git a/doc/component.md b/doc/component.md
index 0c4acdaf..b546929a 100644
--- a/doc/component.md
+++ b/doc/component.md
@@ -337,15 +337,14 @@ This is the opposite method of `mounted`.
### Composition
-The example above shows a QWeb template with a `t-on-click` directive. Widget
-templates are standard [QWeb](qweb.md) templates, but with an extra directive:
-`t-widget`. With the `t-widget` directive, widget templates can declare sub
-widgets:
+The example above shows a QWeb template with a sub component. In a template,
+components are declared with a tagname corresponding to the class name. It has
+to be capitalized.
```xml
some text
-
+
```
@@ -357,22 +356,18 @@ class ParentWidget extends owl.Component {
```
In this example, the `ParentWidget`'s template creates a widget `MyWidget` just
-after the span. The `info` key will be added to the subwidget's props. Each
-props is a string which represents a javascript (QWeb) expression, so it is
+after the span. The `info` key will be added to the subwidget's `props`. Each
+`props` is a string which represents a javascript (QWeb) expression, so it is
dynamic. If it is necessary to give a string, this can be done by quoting it:
-`someString="'somevalue'"`. See the
-[QWeb](qweb.md) documentation for more information on the `t-widget` directive.
+`someString="'somevalue'"`.
Note that the rendering context for the template is the widget itself. This means
that the template can access `state`, `props`, `env`, or any methods defined in the widget.
-The `t-widget` directive is the key to a declarative component
-system. It allows a template to define where and how a sub widget is created
-and/or updated. For example:
```xml
-
+
```
@@ -397,12 +392,11 @@ the subwidget will also be updated automatically.
Note that there are some restrictions on prop names: `class`, `style` and any
string which starts with `t-` are not allowed.
-The `t-widget` directive also accepts dynamic values with string interpolation
-(like the [`t-attf-`](qweb.md#dynamic-attributes) directive):
+The `t-widget` directive can also be used to accept dynamic values with string interpolation (like the [`t-attf-`](qweb.md#dynamic-attributes) directive):
```xml
```
@@ -431,7 +425,7 @@ class that need to be removed. This is why we only support the explicit syntax
with a class object:
```xml
-
+
```
### Event Handling
@@ -463,7 +457,7 @@ event.
A _business_ DOM event is triggered by a call to `trigger` on a component.
```xml
-
+
```
```js
@@ -538,8 +532,8 @@ class Form extends owl.Component {
```xml
-
-
+
+
```
@@ -559,8 +553,8 @@ class Form extends owl.Component {
```xml
-
-
+
+
```
@@ -586,7 +580,7 @@ The `t-model` directive works with ``, ``,
-
+
@@ -604,7 +598,7 @@ Like event handling, the `t-model` directive accepts some modifiers:
For example:
```xml
-
+
```
These modifiers can be combined. For instance, `t-model.lazy.number` will only
@@ -627,7 +621,7 @@ There are three main use cases:
```xml
-
+
```
@@ -836,7 +830,7 @@ Like the `t-on` directive, it can work either on a DOM node, or on a component:
```xml
-
+
```
@@ -894,14 +888,14 @@ Slots are defined by the caller, with the `t-set` directive:
```xml
some widget
-
+
+
```
@@ -933,9 +927,9 @@ be considered the `default` slot. For example:
```xml
-
+ some content
-
+
@@ -979,7 +973,7 @@ Here are a few tips on how to work with asynchronous widgets:
```xml
-
-
+
+
```
diff --git a/doc/qweb.md b/doc/qweb.md
index 60cde467..76244064 100644
--- a/doc/qweb.md
+++ b/doc/qweb.md
@@ -132,7 +132,7 @@ It's API is quite simple:
...
class ParentWidget extends owl.Component { ... }
- qweb.addTemplate("ParentWidget", "
");
+ qweb.addTemplate("ParentWidget", "");
```
## Reference
diff --git a/src/qweb_core.ts b/src/qweb_core.ts
index c3f4f4da..8005bb90 100644
--- a/src/qweb_core.ts
+++ b/src/qweb_core.ts
@@ -346,6 +346,13 @@ export class QWeb {
return;
}
+ const firstLetter = node.tagName[0];
+ if (firstLetter === firstLetter.toUpperCase()) {
+ // this is a component, we modify in place the xml document to change
+ // to
+ node.setAttribute('t-widget', node.tagName);
+ node.nodeValue = 't';
+ }
const attributes = (node).attributes;
const validDirectives: {
diff --git a/src/qweb_extensions.ts b/src/qweb_extensions.ts
index 28034076..9752f39e 100644
--- a/src/qweb_extensions.ts
+++ b/src/qweb_extensions.ts
@@ -208,7 +208,7 @@ const T_WIDGET_MODS_CODE = Object.assign({}, MODS_CODE, {
* explanation of the code generated by the t-widget directive for the following
* situation:
* ```xml
- *
diff --git a/tests/__snapshots__/animations.test.ts.snap b/tests/__snapshots__/animations.test.ts.snap
index 4b31d32c..e99d7742 100644
--- a/tests/__snapshots__/animations.test.ts.snap
+++ b/tests/__snapshots__/animations.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`animations t-transition combined with t-widget 1`] = `
+exports[`animations t-transition combined with component 1`] = `
"function anonymous(context,extra
) {
let utils = this.utils;
diff --git a/tests/__snapshots__/component.test.ts.snap b/tests/__snapshots__/component.test.ts.snap
index abada199..0c0c8049 100644
--- a/tests/__snapshots__/component.test.ts.snap
+++ b/tests/__snapshots__/component.test.ts.snap
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`async rendering delayed t-widget with t-asyncroot directive 1`] = `
+exports[`async rendering delayed component with t-asyncroot directive 1`] = `
"function anonymous(context,extra
) {
let utils = this.utils;
@@ -81,7 +81,7 @@ exports[`async rendering delayed t-widget with t-asyncroot directive 1`] = `
}"
`;
-exports[`async rendering fast t-widget with t-asyncroot directive 1`] = `
+exports[`async rendering fast component with t-asyncroot directive 1`] = `
"function anonymous(context,extra
) {
let utils = this.utils;
@@ -650,7 +650,7 @@ exports[`other directives with t-widget t-on with prevent and self modifiers (or
}
}
if (!w4) {
- let widgetKey4 = \`child\`;
+ let widgetKey4 = \`Child\`;
let W4 = context.widgets && context.widgets[widgetKey4] || QWeb.widgets[widgetKey4];
if (!W4) {throw new Error('Cannot find the definition of widget \\"' + widgetKey4 + '\\"')}
w4 = new W4(owner, props4);
diff --git a/tests/animations.test.ts b/tests/animations.test.ts
index 8d806932..dcaf7cde 100644
--- a/tests/animations.test.ts
+++ b/tests/animations.test.ts
@@ -170,12 +170,12 @@ describe("animations", () => {
expect(spanNode.className).toBe("");
});
- test("t-transition combined with t-widget", async () => {
+ test("t-transition combined with component", async () => {
expect.assertions(5);
env.qweb.addTemplate(
"Parent",
- `