-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
add slots option to component constructor options object #5687
Conversation
export function slot(componentClass: typeof SvelteComponent, options: SvelteSlotOptions): Element[] { | ||
const wrapper = document.createElement('div'); | ||
new componentClass({...options, target: wrapper} as SvelteComponentOptionsPrivate) as any; | ||
// @TODO this is a workaround until src/compiler/compile/render_dom/Block.ts is extended to expose created HTML element |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried but did not know how to modify src/compiler/compile/render_dom/Block.ts to expose created HTML element
44a9731
to
7e65579
Compare
@@ -99,7 +99,7 @@ | |||
"@rollup/plugin-json": "^4.0.1", | |||
"@rollup/plugin-node-resolve": "^6.0.0", | |||
"@rollup/plugin-replace": "^2.3.0", | |||
"@rollup/plugin-sucrase": "^3.0.0", | |||
"@rollup/plugin-sucrase": "^3.1.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rebase against master
you should be able to drop your changes to this file and package-lock.json
. I submitted those as a separate PR in #5758 because that was a big enough change by itself that it took some review. Hopefully that'll make review of this one a bit easier by making this one a bit smaller
This could be done just with I would prefer the plural name, since the object can carry information for multiple slots. If wanted, there can be a This would make your sample look like: // parent.svelte
import { createSlots } from 'svelte';
import MyChild from './mychild.svelte';
new MyCmp({
slots: createSlots({
default: MyChild
})
}); The values can be components, elements, or arrays thereof. Would like to use this with SVG - and it can (I have a project doing that). The PR however currently contains |
@truongsinh this PR has a merge conflict. You will need to rebase against |
This would help a lot when we are trying to write unit tests and we need to programmatically assign something to a slot? |
Any update on the status of these tickets/pull requests? Would love to see this feature added. |
Any update on this? It has pretty big ramifications for testing svelte components? |
looks like this blocks testing slots with vitest and @testing-library/svelte, bummer... |
Are there any updates on this? This prevents us from testing our components well. We need to create slot content to thoroughly test our components with unit tests. |
Would love for this to get worked on! |
@truongsinh just a reminder that this PR needs a rebase |
The lack of the ability to pass slots when creating a component is blocking a lot of people here: testing-library/svelte-testing-library#48 (the two workarounds listed there don't seem to work currently, at least for me — I really don't want to have to use Playwright's experimental component tests to do this!) Please could this make it to release? It's been over two years for this PR… |
Closing Svelte 4 PRs as stale — thank you |
(note that this is addressed in Svelte 5, among other things with the |
This is a continuation of #4296, which tackles #2588 (comment)
This commits also ensures that no extra code is added into
svelte/internal
. Instead, if users want to useslots
API, they will import directly fromsvelte
:Discussions
createSlot, slot
seems really confusing, what would be good names?