Skip to content

Commit

Permalink
fix an issue when listening to events from inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Sep 7, 2023
1 parent 092def5 commit dd04e32
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.DS_Store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quel",
"version": "0.3.4",
"version": "0.3.5",
"description": "Expression-based reactive library for hot listenables",
"main": "dist/commonjs/index.js",
"module": "dist/es/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export function from<EventName extends keyof EventMap>(
): EventSource<EventName>
export function from<EventName extends keyof EventMap>(
node: EventTarget,
name: EventName = 'click' as EventName,
name?: EventName,
options?: boolean | AddEventListenerOptions,
): InputSource | EventSource<EventName> {
if ((node as any).tagName && (
if (!name && (node as any).tagName && (
(node as any).tagName === 'INPUT' || (node as any).tagName === 'TEXTAREA'
)) {
return new InputSource(node as HTMLInputElement)
} else {
return new EventSource(node, name, options)
return new EventSource(node, name ?? 'click' as EventName, options)
}
}
15 changes: 15 additions & 0 deletions src/test/from.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@ describe(from, () => {
expect(cb).toHaveBeenCalledWith('foo')
})
})

test('listens to custom events on textareas.', () => {
testRender((renderer, {render, $}) => {
render(<textarea/>)
const src = from($('textarea').resolveOne()!, 'click')
const cb = jest.fn()

src.get(cb)

expect(cb).not.toHaveBeenCalled()

$('textarea').click()
expect(cb).toHaveBeenCalled()
})
})
})

0 comments on commit dd04e32

Please sign in to comment.