Skip to content

Use e.currentTarget instead of e.target for compatibility with preact/compatΒ #1145

@youzi

Description

@youzi

Hi, I've been trying out your library recently and it's been working very well.

After migrating my project from react to preact using preact/compat, everything seems to work except when editing the number input, I occasionally get:
Uncaught TypeError: Cannot read properties of undefined (reading 'setSelectionRange') which is here:

onFocus: (e3) => e3.target.setSelectionRange(highlight ? 0 : e3.target.value.length, e3.target.value.length)

which seems to be here:

e.target.setSelectionRange(highlight ? 0 : e.target.value.length, e.target.value.length)

I suspect this has to do with the fact that preact uses the regular dom events vs reacts synthetic events (see: https://preactjs.com/guide/v10/differences-to-react/#main-differences).

I expect that using e.currentTarget here (and in other places where you use e.target) will resolve this issue. This should work with react as well and would make this project fully compatible with preact/compat.

Would you be open to updating this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions