minwork / use-long-press

React hook for detecting click (or tap) and hold event
MIT License
122 stars 12 forks source link

Event is missing currentTarget #26

Closed paulincai closed 2 years ago

paulincai commented 2 years ago

Scenario: I want to long press on a React functional component with children. E.g in a list I have a contact with photo, name, status. I want to long press on the upper component that wraps the entire contact.

Presently the Event is bound to the clicked/touched selector (either photo, or name, or status). Technically this should be bound to the selector that the {...bind} is attached to.

e.target.id on long press on the next component should be 'x' e.currentTarget does not exist

<div id='x' {...bind}>
    <...photo  />
    <...name  />
    <s...status />
</div>
paulincai commented 2 years ago

ok, apparently I can get the currentTarget from onStart event (more correct actually on onFinish). However I believe the selector returned should be the one which this library binds to.

minwork commented 2 years ago

Hey @paulincai, the behavior you are describing are actually fully handled by React. bind contains only handlers for standard react events like onMouseDown and it passes received event untouched (with an exception of persisting it). https://github.com/minwork/use-long-press/blob/7bda6f76d6cd842e8f82c4c67adfd1a3aea09798/src/index.ts#L245-L256 https://github.com/minwork/use-long-press/blob/7bda6f76d6cd842e8f82c4c67adfd1a3aea09798/src/index.ts#L152-L153 https://github.com/minwork/use-long-press/blob/7bda6f76d6cd842e8f82c4c67adfd1a3aea09798/src/index.ts#L166-L171

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.