Skip to content

Commit 4db6acb

Browse files
committed
Fix inconsistent templates rendering by nested components
1 parent d7f5d41 commit 4db6acb

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
## Unreleased
2+
3+
### Breaking changes
4+
5+
- Item template defined in `dxi-item` and `dxTemplate` now works consistently.
6+
7+
Previously, the result of the `dxi-item` in the DxList was rendered as follows:
8+
```html
9+
<div class="dx-item-content">
10+
<dxi-item>...</dxi-item>
11+
</div>
12+
```
13+
14+
Currently, this will be rendered as follows:
15+
```html
16+
<dxi-item class="dx-item-content">
17+
...
18+
</dxi-item>
19+
```
20+
121
## 16.2.3-rc.4 (2017-01-13)
222

323
### Features

src/core/nested-option.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { QueryList, ElementRef } from '@angular/core';
22

3+
declare function require(params: any): any;
4+
let $ = require('jquery');
5+
6+
import { DX_TEMPLATE_WRAPPER_CLASS } from './template';
7+
38
export interface INestedOptionContainer {
49
instance: any;
510
}
@@ -138,8 +143,12 @@ export function extractTemplate(option: OptionWithTemplate, element: ElementRef)
138143
}
139144

140145
option.template = {
141-
render: (options) => {
142-
return options.container.append(element.nativeElement);
146+
render: (renderData) => {
147+
if (renderData.container) {
148+
renderData.container.append(element.nativeElement);
149+
}
150+
return $(element.nativeElement)
151+
.addClass(DX_TEMPLATE_WRAPPER_CLASS);
143152
}
144153
};
145154
}

src/core/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { DxTemplateHost } from './template-host';
1313
declare function require(params: any): any;
1414
let $ = require('jquery');
1515

16-
const DX_TEMPLATE_WRAPPER_CLASS = 'dx-template-wrapper';
16+
export const DX_TEMPLATE_WRAPPER_CLASS = 'dx-template-wrapper';
1717

1818
export class RenderData {
1919
model: any;

templates/nested-component.tst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { <#= it.baseClass #> } from '<#= it.basePath #>';
2121
@Component({
2222
selector: '<#= it.selector #>',
2323
template: '<#? it.hasTemplate #><ng-content></ng-content><#?#>',
24+
styles: ['<#? it.hasTemplate #>:host { display: block; }<#?#>'],
2425
providers: [NestedOptionHost]<#? it.inputs #>,
2526
inputs: [<#~ it.inputs :input:i #>
2627
'<#= input.name #>'<#? i < it.inputs.length-1 #>,<#?#><#~#>

tests/src/ui/list.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ describe('DxList', () => {
111111
expect(instance.element().find('.dx-item-content').eq(1).text()).toBe('Item 2');
112112
}));
113113

114+
it('should have correct item template', async(() => {
115+
TestBed.overrideComponent(TestContainerComponent, {
116+
set: {
117+
template: `
118+
<dx-list>
119+
<dxi-item>item</dxi-item>
120+
</dx-list>
121+
`
122+
}
123+
});
124+
let fixture = TestBed.createComponent(TestContainerComponent);
125+
fixture.detectChanges();
126+
127+
let instance = getWidget(fixture);
128+
expect(instance.element().find('.dx-item-content').html()).toBe('item');
129+
expect(instance.element().find('.dx-item-content').css('display')).toBe('block');
130+
}));
131+
114132
it('should react to item option change', async(() => {
115133
TestBed.overrideComponent(TestContainerComponent, {
116134
set: {

0 commit comments

Comments
 (0)