Coder Social home page Coder Social logo

himynameisdave / browser-event-utils Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 2.0 2.68 MB

๐ŸŽŸ A collection of higher-order functions for invoking common browser event methods.

Home Page: https://himynameisdave.github.io/browser-event-utils

License: MIT License

TypeScript 94.97% JavaScript 5.03%
utilities browser-events higher-order-functions event-handling preventdefault stoppropagation keyboard keypress event-target

browser-event-utils's People

Contributors

dependabot[bot] avatar fossabot avatar himynameisdave avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

browser-event-utils's Issues

Fix the $TSFixMe (any alias) type definitions

Issuehunt badges

Fix all the $TSFixMe (alias for any) type definitions by providing real type definitions for them.

This was added as a placeholder because there were a few places where I didn't know the best way to define types.

I would like help with this issue, not just to have stronger typing in this package, but also as a learning exercise so that I better understand complex typing.

Acceptance Criteria


IssueHunt Summary

Backers (Total: $5.00)

Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Add withNumericTargetValue

Sometimes you want event.target.value to be a number. Unfortunately the browser always casts it to a string (even for numeric inputs) -- see example. Would be nice to have a helper which casts it to a number for you ๐Ÿ‘

Docs: Add CodeSandbox examples

Add CodeSandbox examples to docs. This will help folks onboard easier and play around with stuff, and is also a good way to test stuff in browserland.

Increase test coverage

In the 80%+ range is nice, but 100% would give consumers more confidence in this package.

Feat: withDebouncedEvent

Add withDebouncedEvent, so that keyboard events (or other events like clicking and scrolling) can be debounced.

Add withSelectOnFocus

withSelectOnFocus would attempt to call event.target.select() if it exists. The idea is that this would be passed to onFocus and could be used to create focus-and-select style inputfields.

Feat: Add withTargetChecked

To replace stuff like this...

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    setChecked(event.target.checked);
};

We could do:

const handleChange = withTargetChecked(setChecked);

Uncaught TypeError: Illegal invocation

Describe the bug

When using withPreventDefault in a standard/template Rollup + Svelte project, I get the following error: Uncaught TypeError: Illegal invocation

It seems to be pointing to this line in callIfExists, which the compiler spits out as this:

return (_a = event === null || event === void 0 ? void 0 : event[method]) === null || _a === void 0 ? void 0 : _a();

Where invoking _a() seems to be causing the bug.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the svelte template repo.
  2. yarn add browser-event-utils@next
  3. Wrap an event handler with withPreventDefault:
<script>
  import { withPreventDefault } from 'browser-event-utils';

  const handleDrop = withPreventDefault(() => { //... });
</script>

<div on:drop={handleDrop}>
  Drop here!
</div>
  1. Invoke the event, you should see the error.

Expected behavior

It should just call the expected method, no errors.

Versions (please complete the following information):

  • browser-event-utils Version: [eg: v3.0.0-beta.5]
  • Browser & Version: Google Chrome 83.0.4103.106
  • Framework version (if applicable) [eg: [email protected]]
  • (Optionally) NodeJS Version: v12.16.3

Additional context or comments
Add any other context about the problem here.

withTargetValue

Description

A utility that grabs the event.target.value (if it exists) and passes it along as the first argument to the provided function, followed by the full event object.

Sample usage:

import { withTargetValue } from 'browser-event-utils';

const input = document.querySelector('input');
input.addEventListener('change', withTargetValue((value, event) => {
    console.log(`The value is ${value}`)
}));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.