Skip to content

Feature Suggestion: Transition Forwarding #7477

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

Closed
brandonmcconnell opened this issue Apr 21, 2022 · 3 comments
Closed

Feature Suggestion: Transition Forwarding #7477

brandonmcconnell opened this issue Apr 21, 2022 · 3 comments

Comments

@brandonmcconnell
Copy link
Contributor

brandonmcconnell commented Apr 21, 2022

Describe the problem

Currently, there appears to be no way to pass a transition to an element in a nested component. For a standard <button> DOM element, you could do something like this:

<script>
  import { fade } from 'svelte/transition';
</script>

<button trasition:fade>Gather ye rosebuds while ye may</button>

If you wanted to apply the same transition to a button element within a Button component, there is no way to forward that transition down, or even pass the transition down as a prop and then implement it in the nested button.

Describe the proposed solution

This would be an ideal implementation, being able to import the desired transition into the top-level component and then pass it into the component:

<!-- App.svelte -->

<script>
  import { fade } from 'svelte/transition';
  import Button from './Button.svelte';
</script>

<Button transition:fade>Old Time is still a-flying</Button>

<!-- Button.svelte -->

<script>
  export let transition;
</script>

<button transition:{transition}><slot /></button>

Alternatives considered

The alternative I see, which is not idea, would be to wrap the component in a DOM element and apply the transition on the DOM element instead, like this:

<!-- App.svelte -->

<script>
  import { fade } from 'svelte/transition';
  import Button from './Button.svelte';
</script>

<div transition:fade>
  <Button>Old Time is still a-flying</Button>
</div>

<!-- Button.svelte -->

<button><slot /></button>

Importance

would make my life easier

@kevmodrome
Copy link
Contributor

Transitions are just functions, so you can actually apply a transition that has been passed down as a prop:

<!-- App.svelte -->

<script>
  import { fade } from 'svelte/transition';
  import Button from '.Button.svelte';
</script>

<Button transition={fade}>Old Time is still a-flying</Button>

<!-- Button.svelte -->

<script>
  export let transition;
</script>

<button transition:transition><slot /></button>

@brandonmcconnell
Copy link
Contributor Author

@kevmodrome Wow for some reason, I tried this in a REPL earlier and could've sworn it didn't work but it does. Thank you for clarifying this! 🙏🏼

@Tropix126
Copy link

Also, if you're interested you can have a look at this RFC of mine which covers forwarding using the actual transition directive - sveltejs/rfcs#60

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

3 participants