Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration: using HTMLTemplateElement inside CustomElements #9427

Open
riovir opened this issue Feb 5, 2019 · 0 comments
Open

Integration: using HTMLTemplateElement inside CustomElements #9427

riovir opened this issue Feb 5, 2019 · 0 comments

Comments

@riovir
Copy link

riovir commented Feb 5, 2019

What problem does this feature solve?

Conveniently using Custom Elements that require both prop bindings and HTMLTemplateElements together with Vue templates.

Related fixed bug: #8041

The fix unfortunately doesn't allow the parent of the HTMLTemplateElement to retain its prop bindings with Vue.

The use case is similar to the scoped slot feature of Vue, but with Custom Elements. It's clear that without a special directive Vue will not assume the <template> is expected to be a HTMLTemplateElement.

Assumptions:

  • Using v-pre on the parent breaks prop bindings
  • Using v-pre on the child template still makes Vue skip rendering the <template> element
  • This behavior of v-pre is intended

JsFiddle:

Attempts at the problem and desired solution. https://jsfiddle.net/qhkb6sof/2/

What does the proposed API look like?

The v-native directive, marking a tag to be rendered as the native DOM element of the same name.

Since there is a proposal on the way to allow mustache-style expressions inside HTMLTemplateElements v-pre might still be needed to avoid Vue interpreting the internals.

Only using the already present v-pre would be nice, but I'm unsure how much of the already established behavior it would break.

<x-filtered-list :items.prop="['one', 'two', 'three']" search="t">
  <!-- The template is intended to represent the "native" HTMLTemplateElement, which needs to be rendered -->
  <template v-native v-pre>
    <!-- The expression below expected to be ignored by Vue and rendered as is  -->
    <li>{{text}}</li>
  </template>
</x-filtered-list>

The resulting DOM should look like this in inspection:

<x-filtered-list search="t">
  <template>
    #document-fragment
      <li>{{text}}</li>
  </template>
</x-filtered-list>

Ideally <li>{{text}}</li> ends up in the #document-fragment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant