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

Svelte 5: this type of directive is not valid on components #12236

Closed
orefalo opened this issue Jun 30, 2024 · 4 comments
Closed

Svelte 5: this type of directive is not valid on components #12236

orefalo opened this issue Jun 30, 2024 · 4 comments

Comments

@orefalo
Copy link

orefalo commented Jun 30, 2024

Describe the problem

the analysis around the current props limitation on component has the following shortcomings:

  • it is not intuitive, why can I do <div class:rtl={isRTL}/> and not <MyComp class:rtl={isRTL}/>.
  • It forces the css classes as global, which break proper encapsulation
  • It makes the alternative code seem unpolished and difficult to read.

consider the code below:

<MyComp
 class={`tree${rtl ? ' tree--rtl rtl' : ''}${dragOvering ? 'tree--drag-overing drag-overing' : ''}`} />

Describe the proposed solution

allow myprop:somevalue={condition} manipulations on all elements, HTMLElement or Components.

The above code could be rewritten as:

<MyComp
  class="tree"
  class:tree--rtl={rtl}
  class:rtl={rtl}
  class:tree--drag-overing={dragOvering}
  class:drag-overing={dragOvering} />

for the following benefits:

  • it's intuitive
  • it enforces proper css encapsulation
  • clarity: it's easy to read
  • requires no learning curve, it's been used on HTMLElement

thinking beyond class:, the same construct could be used for any prop (value:me={user==="olivier") or any other myprop:somevalue={condition}). Similar constructs are possible with other frameworks.

In summary, the proposal is more Svelte.

Importance

would make my life easier

@orefalo
Copy link
Author

orefalo commented Jun 30, 2024

This time around it's a Feature request

@MotionlessTrain
Copy link
Contributor

Note that this would not work for all attributes on HTMLElements: in particular, it would clash with the style directive (style:css-attribute={value})

@7nik
Copy link
Contributor

7nik commented Jun 30, 2024

Duplicate of #12229 - issue type (bug report/feature request/etc.) doesn't matter - it was closed because there already is an issue (no matter whether opened or closed) for this topic.

@orefalo
Copy link
Author

orefalo commented Jul 1, 2024

closing, still I find the current limitation non intuitive

@orefalo orefalo closed this as completed Jul 1, 2024
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