uNmAnNeR / imaskjs

vanilla javascript input mask
https://imask.js.org
MIT License
4.96k stars 258 forks source link

useIMask doesn't add event listener accept & complete on some cases #1078

Open baran-ozer opened 2 months ago

baran-ozer commented 2 months ago

Describe the bug When I render my dom elements optionally I have deteced that useIMask hook can't add event listener to my input.

To Reproduce You can see this error on reactplayground. IMask on input works correctly but it doesn't update IMask value since there is no accept and complete event on my input. When dom loads IMask https://github.com/uNmAnNeR/imaskjs/blob/d1fe83e20addb1dc217f2c126e4e2b78aaf1c6be/packages/react-imask/src/hook.ts#L142-L154 this hook above triggers once but imask.ref is empty so it can't attach event listeners, then on second render(when isLoading state setted to false on my playground code) this hook never triggers again.

Expected behavior A clear and concise description of what you expected to happen.

Environment:

Additional context I have fixed this issue by updating this dependency hook: https://github.com/uNmAnNeR/imaskjs/blob/d1fe83e20addb1dc217f2c126e4e2b78aaf1c6be/packages/react-imask/src/hook.ts#L142-L154 I can open a PR for this if you agree that this is a bug.