Skip to content

Commit

Permalink
🐛 Enabled morphing @event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ekwoka committed Mar 29, 2023
1 parent 6142a83 commit 7f249c5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/morph/src/morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function morph(from, toHtml, options) {
let value = toAttributes[i].value

if (from.getAttribute(name) !== value) {
from.setAttribute(name, value)
from.setAttribute(name.replace(/^@/,Alpine.prefixed('on:')), value)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/cypress/integration/plugins/morph.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,23 @@ test('can morph with flat-nested conditional markers',
get('div:nth-of-type(3) input').should(haveValue('bar'))
},
)

// '@event' handlers cannot be assigned directly on the element
test('can morph @event handlers', [
html`
<div x-data="{ foo: 'bar' }">
<button x-text="foo"></button>
</div>
`],
({ get, click }, reload, window, document) => {
let toHtml = html`
<button @click="foo = 'buzz'" x-text="foo"></button>
`;

get('button').should(haveText('bar'));

get('button').then(([el]) => window.Alpine.morph(el, toHtml));
get('button').click();
get('button').should(haveText('buzz'));
}
);

0 comments on commit 7f249c5

Please sign in to comment.