Is your feature request related to a problem? Please describe.
I have an iterated list of anchor tags and the data that drives them may enable/disable them. Based on the HTML spec of an anchor tag, the href is an OPTIONAL attribute. Presently, I cannot omit the href attribute conditionally because svelte does not have a facility to do so.
Describe the solution you'd like
I would like to be able to conditionally withhold from rendering an attribute. It is not enough to render the href with a null/empty-string value as the behavior of those is different. Browsers treat an empty-string href as a valid href to the existing page (and are also accessible via tab), whereas an anchor tag, without the attribute all together, will have no on-click functionality (and are not focusable via tab).
Describe alternatives you've considered
I have considered changing the tag conditionally to something other than an anchor when disabled. Since svelte does not allow me to render an opening html tag inside a condition without closing it in the same condition, this complicates this approach. There is enough logic in the child elements to make it not very DRY to duplicate the block in both instances. There is also not ENOUGH logic to warrant a separate component for the children.
How important is this feature to you?
As there are potential work-arounds for this, it is not 100% mission critical. However I do feel like this is a pretty important issue in general (and one svelte has punted on in the past). We should have more flexibility in what attributes are rendered in the final output, and not be forced into null or empty values because we opted into a conditional statement.
Additional context
The relevant statement in the anchor spec: https://html.spec.whatwg.org/multipage/links.html#attr-hyperlink-href
If you set the attribute to null or undefined, it should be completely absent on the element (which is indeed different from it being an empty string). <a href={null}>. This was added in 3.5.2. Is this not what you're seeing?
sure enough it is doing that! my apologies 馃憤
Most helpful comment
If you set the attribute to
nullorundefined, it should be completely absent on the element (which is indeed different from it being an empty string).<a href={null}>. This was added in 3.5.2. Is this not what you're seeing?