Skip to content

fix: patch renderer function instead of the template - #2481

Merged
tomivirkki merged 6 commits into
masterfrom
fix-lit-renderer-editor
Jan 10, 2022
Merged

tomivirkki merged 6 commits into
masterfrom
fix-lit-renderer-editor

Conversation

@tomivirkki

@tomivirkki tomivirkki commented Jan 7, 2022 •

Copy link
Copy Markdown
Member

FIxes #2465

The current implementation of EditorRenderer modifies the <template> element of a grid column so that its initial content gets wrapped inside a dom-if and another dom-if with the editor component renderer is added inside the same template.

<vaadin-grid-column>
  <template>
    Original content
  </template>
</vaadin-grid-column>

EditorRenderer.setupEditorTemplate(...) ->

<vaadin-grid-column>
  <template>
    <template is='dom-if' if='[[item._editing]]'>
      Editor component      
    </template>
    <template is='dom-if' if='[[!item._editing]]'>
      Original content
    </template>
  </template>
</vaadin-grid-column>

If a column uses LitRenderer, there's no <template> element involved, so this doesn't work.

This PR changes EditorRenderer so that instead of modifying the <template> element (which may not be there), it patches the renderer function of the column to conditionally either render the editor component or use the original function. Other than patching the renderer function instead of the <template> element, the concept stays mostly the same.

The renderer approach also works with ComponentRenderer and the deprecated TemplateRenderer, because since Vaadin 21, they also use the renderer function under the hood (via template-renderer adapter).

@tomivirkki
tomivirkki marked this pull request as draft January 7, 2022 11:42
@tomivirkki
tomivirkki force-pushed the fix-lit-renderer-editor branch from 0d1ba4a to b6700ab Compare January 7, 2022 12:38
"}" +

// If editing, render the editor, otherwise use the original renderer
"if (root.__editing) { root.innerHTML = `" + editorTemplate + "` }" +

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editor template was previously rendered here


// If editing, render the editor, otherwise use the original renderer
"if (root.__editing) { root.innerHTML = `" + editorTemplate + "` }" +
"else if (!originalRender) { root.textContent = model.item." + columnInternalId + " }" +

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fallback mechanism for columns without a renderer function. Previously here

@tomivirkki
tomivirkki marked this pull request as ready for review January 7, 2022 14:53

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for the changes in JS code (renderer looks about right).

@tomivirkki
tomivirkki enabled auto-merge (squash) January 10, 2022 13:53
@tomivirkki
tomivirkki merged commit 736a35a into master Jan 10, 2022
@tomivirkki
tomivirkki deleted the fix-lit-renderer-editor branch January 10, 2022 13:53
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 23.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Grid Editor not working when column uses LitRenderer

5 participants