Skip to content

Commit 8ffbdc1

Browse files
author
Elson Correia
committed
fix overriding the event in the props
1 parent b45f3ca commit 8ffbdc1

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@beforesemicolon/markup",
3-
"version": "1.13.3",
3+
"version": "1.13.4",
44
"description": "Reactive HTML Templating System",
55
"engines": {
66
"node": ">=18.16.0"

src/html.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import '../test.common.ts';
22
import { html, HtmlTemplate } from './html.ts'
33
import { effect, state } from './state.ts'
44
import {when, repeat, oneOf, is, element, suspense} from './helpers/index.ts'
5+
import { text } from 'node:stream/consumers'
6+
import exp = require('node:constants')
57

68
describe('html', () => {
79

@@ -842,6 +844,27 @@ describe('html', () => {
842844
expect(countUpSpy).toHaveBeenCalledWith(expect.any(Event));
843845
})
844846

847+
it('should override attribute in the object', () => {
848+
const clickMock1 = jest.fn();
849+
const clickMock2 = jest.fn();
850+
851+
const props = {
852+
onclick: clickMock1,
853+
type: 'submit'
854+
}
855+
856+
const temp = html`<button ${props} type="button" onclick="${clickMock2}" ref="btn">click me</button>`.render(document.body)
857+
858+
const [btn] = temp.refs['btn'] as HTMLButtonElement[];
859+
860+
expect(document.body.innerHTML).toBe('<button type="button">click me</button>');
861+
862+
btn.click();
863+
864+
expect(clickMock1).not.toHaveBeenCalled()
865+
expect(clickMock2).toHaveBeenCalled()
866+
})
867+
845868
it('should handle input value', () => {
846869
const [value, setValue] = state("");
847870

src/html.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -187,22 +187,24 @@ function createTemplate(
187187

188188
const isRef = name === 'ref'
189189

190+
!isRef && slots.remove(attrSlots[name])
191+
190192
if (isRef || /\$val([0-9]+)/.test(value)) {
191193
__self__.setAttribute('data-slot-id', id)
192194
const v = value.trim()
193-
return slots.push({
195+
196+
attrSlots[name] = {
194197
type: 'attribute',
195198
name,
196199
value: v,
197200
nodeSelector: `[data-slot-id="${id}"]`,
198201
valueParts: isRef ? [v] : parseDynamicRawValue(v),
199-
})
202+
}
203+
204+
return slots.push(attrSlots[name])
200205
}
201206

202207
setElementAttribute(__self__, name, value)
203-
204-
// ensure prop attributes do not override inline attributes
205-
slots.remove(attrSlots[name])
206208
},
207209
} as unknown as ElementLike
208210
},

0 commit comments

Comments
 (0)