Skip to content

Polymer's declarative event listener names have issues with casing #4888

Description

@sorvell

Polymer adds event listeners to elements declaratively using attribute names in HTML as input. For example, <a on-click="foo"> in an element template adds a listener as if the user did: <a>.addEventListener('click', e => this.foo(e)).

Since HTML attribute names are not case sensitive, supporting any casing requires a convention. For properties Polymer does dash->camel casing to map attribute names to properties names (foo-bar becomes fooBar) but it does not do this for events. Notably Polymer notification events include dashes (e.g. name-changed) so we expect lots of user code relies on this convention.

This means that it's currently not possible to declaratively listen to events like camelEvent, CAPSEvent, or PascalEvent.

We could consider introducing a new syntax to support this. A couple of options:

  • Use _ in events to indicate "remove the _ and replace the next character with uppercase".
  • Add a special attribute name like polymer-events within which the value is used to declare events like `polymer-events="lowercaseevent: handler1, cameEvent: handler2, CAPSEvent: handler3" ...

This will cause Polymer to fail ~6 tests (as of this issue) at https://custom-elements-everywhere.com/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions