Skip to content

Commit

Permalink
add handleTargetValue to lib/dom.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Feb 28, 2023
1 parent d21eb6e commit 37d99fc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# changelog

## 0.7.2

- add `handleTargetValue` to `$lib/dom.ts`

## 0.7.1

- make `select` elements count for `isEditable`
Expand Down
8 changes: 8 additions & 0 deletions src/lib/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ export const swallow = <T extends Event>(event: T, immediate = true, preventDefa
}
return event;
};

// TODO improve these types, the motivation was the strictness of Svelte DOM types
export const handleTargetValue =
(cb: (value: any, event: any) => void, swallowEvent = true) =>
(e: any): void => {
if (swallowEvent) swallow(e);
cb(e.target.value, e);
};

0 comments on commit 37d99fc

Please sign in to comment.