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

feat : support transition with hidden (poc) #13576

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

adiguba
Copy link
Contributor

@adiguba adiguba commented Oct 11, 2024

A possible solution for #9976

It's simple to show/hide a node with the hidden attribute (of style:display), but there no way to use the svelte's transition with that, and the {#if} block destroys its contents every time the condition changes, which is not necessarily desirable.

This PR proposes a new modifier for the transition: directive : hidden.
With this modifier, the transition will only be applied when the hidden attribute is modified.

Example :

<div transition:slide|hidden={options} hidden={condition}>

</div>

This would allow to show/hide elements using Svelte transitions.

Demo REPL here (edit : modified REPL to use |this instead of |hidden)

Remarks :

  • I don't really like the modifier's name hidden, but I couldn't find a better name...
  • The implementation is quite simple.
  • I just realized that this doesn't work with spreading, but I think it should be relatively easy to implement.
  • Compatible SSR without change, as the hidden attribute will be set.
  • Caveat : the hidden attribute is overridden by any CSS display value.
    It's required to have a global CSS like that :
[hidden] {
    display: none !important;
}

Is it worth it?

Svelte 5 rewrite

Please note that the Svelte codebase is currently being rewritten for Svelte 5. Changes should target Svelte 5, which lives on the default branch (main).

If your PR concerns Svelte 4 (including updates to svelte.dev.docs), please ensure the base branch is svelte-4 and not main.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

Copy link

changeset-bot bot commented Oct 11, 2024

⚠️ No Changeset found

Latest commit: f5f6317

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@adiguba
Copy link
Contributor Author

adiguba commented Oct 14, 2024

For the naming, perhaps we could use different directive, for example by replacing transition:/in:/out: with someting like view:/show:/hide:

-<div transition:slide|hidden={options} hidden={condition}></div>
+<div view:slide={options} hidden={condition}></div>

-<div in:slide|hidden={options} out:fade|hidden={options} hidden={condition}></div>
+<div show:slide={options} hide:fade={options} hidden={condition}></div>

fix bug with in:/out: directive
support for spreading with set_attributes()
@adiguba
Copy link
Contributor Author

adiguba commented Oct 14, 2024

I fixed some bug with in: & out: directive, and support for spreading with set_attributes().
I also changed the modifier from |hidden to |this which I think is a little more explicit...

@adiguba
Copy link
Contributor Author

adiguba commented Oct 17, 2024

Just see #13612
I didn't know that hidden could take other values, which conflicts a bit with this PR... :/

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

Successfully merging this pull request may close these issues.

1 participant