Skip to content

Spread JS event map #612

@iamajoe

Description

@iamajoe

Sorry in advance in case I have missed an issue related to this.

There are cases where a map[string]templ.ComponentScript might make sense but spreading or iterating is not possible on the attributes side. Tried to do a spread with templ.Attributes but those are not templ scripts so it makes sense that they do not work.

jsMap := map[string]templ.ComponentScript{
  "onclick": alert(),
}

Example A (spread):

<button { jsMap... }>Foo</button>

Example B (for):

<button
for evt, fn := range jsMap {
  {evt}={fn}
}
>Foo</button>

Personally I think it would be better to support a for under attributes. Also, a for even for templ.Attributes would be interesting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions