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

Using HTML attributes from specification in kebab-case #10363

Closed
alkorlos opened this issue Feb 1, 2024 · 2 comments
Closed

Using HTML attributes from specification in kebab-case #10363

alkorlos opened this issue Feb 1, 2024 · 2 comments

Comments

@alkorlos
Copy link

alkorlos commented Feb 1, 2024

Describe the problem

Now there is no good way to use native HTML attributes in kebab-case as they are defined in the specification.

In Svelte need to specify all prop, can't just use native attributes.

For example component SvgIcon:

<svg aria-label={label}></svg>

<script>
  export let label;
</script>

And use it:

<SvgIcon label="lorem"></SvgIcon>

Now is no good way use it like <SvgIcon aria-label="lorem"></SvgIcon>
Every frontend developer knows the aria-label attribute and what it does, but it cannot be used. All possible options like ariaLabel, aria_label and so on are not standard and less understandable.

It can be done with export let label = $$props['aria-label'];, but, if I understood the documentation correctly, it's better not to do this due to performance issues.

Describe the proposed solution

I see #3852, but the discussion was about warnings and custom attributes in kebab-case, maybe implementing the ability to use native attributes would be easier? Using a whitelist?

There can be many options with different syntax. For example:

Function overriding the attribute name:

  export let label;
  defineAttribute(label, "aria-label");

Defining the attribute name during assignment:

  export let label = { value: undefined, attribute: "aria-label" };

Special object accepting attributes from a whitelist:

export let standartAttributes = {
  'class': undefined,
  'aria-label': 'lorem'
};

Either way, the ability to use attributes in HTML as defined in the specification will make the code more understandable.

Importance

would make my life easier

@dummdidumm
Copy link
Member

Closing as duplicate of #3852 . This will be possible to do in Svelte 5, see the last comment in the linked issue.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
@alkorlos
Copy link
Author

alkorlos commented Feb 1, 2024

@dummdidumm Thank you! You last comment in #3852 realy missed a couple of hours ago

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

2 participants