vuejs / vuejs/core

Allow components passed as slot prop to be used in the slot

Open
#8,553 11 comments 23 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

:sparkles: feature request
Dominant language
TypeScript
Stars
54.4k
Forks
9.2k
Avg merge
1d 5h
Merged PRs (30d)
140

Description

What problem does this feature solve?

Example:

<template>
  <SomeComponent v-slot="{ SpecializedComponent }">
    <SpecializedComponent />
  </SomeComponent>
</template>

At the moment, vue does not consider components passed as slot property on render. Instead it complains about "SpecializedComponent" being unknown.

Why is this useful:

  1. Allow to render parent-child relationships in an easy way:

This basically allows to wrap the inner content of a parent component with some custom styling or whatnot.
A similar concept is used in vue-router to display the current page (<router-view>)

<template>
  <Table>
    <template #td="{ Child }">
      <td style="background: red">
        <Child />
      </td
    </template>
  </Table>
</template>
  1. Allow typed components that rely on props passed to the parent component
<template>
  <Table :data="typedData" v-slot="{ Column }">
    <Column prop="willErrorWithWrongKey" />
    <Column v-slot="{ row }">
      {{ row.typedProperties }}
    </Column>
  </Table>
</template>

Both cases are extremely useful for different reasons

What does the proposed API look like?

See above or look at this playground

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Vue Playground reproduction and compare both examples: rendering a component supplied through slot props and preserving the typed component props. Done means slot-provided components render without an unknown-component warning and the demonstrated typed usages work as proposed.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.