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

Find a way to allow "@" in attribute? #235

Open
Haroenv opened this issue Jan 17, 2023 · 0 comments
Open

Find a way to allow "@" in attribute? #235

Haroenv opened this issue Jan 17, 2023 · 0 comments

Comments

@Haroenv
Copy link

Haroenv commented Jan 17, 2023

Both Vue and Alpine have this weird syntax where events get preceded by @. I'm using htm in a library for templating. Preact is more of an implementation detail, and not really exposed to users. I'm seeing someone who uses alpine on the rest of the page and wants an event handler that's handled by alpine in that template. Unfortunately the shorthand syntax doesn't seem to work due to setAttribute.

A reproduction is:

import { render } from "preact";
import { html } from "htm/preact";

// does work
render(
  html`
    <div x-data="{ open: false }">
      <button @click="open = !open">Expand</button>

      <span x-show="open">
        Content...
      </span>
    </div>
  `,
  document.body
);

(workaround is replacing @ to x-on:, but our user wasn't aware of this)

sandbox: https://codesandbox.io/s/festive-wildflower-qeugtn?file=/src/index.js

other relevant issues:
alpinejs/alpine#1235
alpinejs/alpine#396
algolia/instantsearch#5435

I'm guessing no workaround will be possible as it's actually setAttribute throwing, but I wonder if you know something that would avoid users changing their expectations.

@Haroenv Haroenv changed the title Find a way to allow "@" in attribute Find a way to allow "@" in attribute? Jan 17, 2023
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

1 participant