Skip to content

Commit

Permalink
Remove model from renderer arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
sohrabtaee committed Jul 19, 2018
1 parent 63aa688 commit a54cd7e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo/dialog-basic-demos.html
Expand Up @@ -35,7 +35,7 @@ <h3>Content Renderer Function</h3>
window.addDemoReadyListener('#dialog-renderer-function-demo', function(document) {
const dialog = document.getElementById('dialog-renderer');

dialog.renderer = function(root, model, dialog) {
dialog.renderer = function(root, dialog) {
if (root.firstChild) {
return;
}
Expand Down
9 changes: 2 additions & 7 deletions src/vaadin-dialog.html
Expand Up @@ -124,18 +124,13 @@

/**
* Custom function for rendering the content of the dialog.
* Receives arguments `root`, `owner`, `model`
* Receives arguments `root`, `dialog`
*
* `root` The root container element. Users are able to append content to it.
*
* `owner` The host element of the renderer function.
*
* `model` null
* `dialog` The host element of the renderer function.
*
* **NOTE:** The renderer callback can be called multiple times with the previous content
*
* **NOTE:** `dialog` does not have any specific properties to pass with the `model` object,
* it is set to null.
*/
renderer: Function,

Expand Down
38 changes: 32 additions & 6 deletions test/vaadin-dialog_renderer-test.html
Expand Up @@ -12,28 +12,54 @@

<body>

<test-fixture id="renderer-function">
<test-fixture id="renderer-function-without-template">
<template>
<vaadin-dialog></vaadin-dialog>
</template>
</test-fixture>

<test-fixture id="renderer-function-with-template">
<template>
<vaadin-dialog>
<template>
<div>Renderer Function</div>
<div>Template content</div>
</template>
</vaadin-dialog>
</template>
</test-fixture>

<script>
describe('renderer function', () => {
describe('renderer function without template', () => {
let dialog, overlay;

beforeEach(() => {
dialog = fixture('renderer-function-without-template');
overlay = dialog.$.overlay;
});

it('should render the content of renderer function when renderer function provided', () => {
dialog.renderer = (root, dialog) => {
const div = document.createElement('div');
div.textContent = 'The content of the dialog';
root.appendChild(div);
};
dialog.opened = true;

expect(overlay.textContent).to.include('The content of the dialog');
});
});

describe('renderer function with template', () => {
let dialog, overlay;

beforeEach(() => {
dialog = fixture('renderer-function');
dialog = fixture('renderer-function-with-template');
overlay = dialog.$.overlay;
});

it('should default to template if renderer function not provided', () => {
dialog.opened = true;
expect(overlay.textContent).to.include('Renderer Function');
expect(overlay.textContent).to.include('Template content');
});

it('should render the content of renderer function instead of template content when renderer function provided', () => {
Expand All @@ -59,7 +85,7 @@

dialog.renderer = null;

expect(overlay.textContent).to.include('Renderer Function');
expect(overlay.textContent).to.include('Template content');
});
});
</script>
Expand Down

0 comments on commit a54cd7e

Please sign in to comment.