taiga-family / maskito

Collection of libraries to create an input mask which ensures that user types value according to predefined format.
https://maskito.dev
Apache License 2.0
1.42k stars 32 forks source link

🐞 - Input element masked with date range mask fires InputEvent twice first time #879

Closed ko1ebayev closed 9 months ago

ko1ebayev commented 9 months ago

Which package(s) are the source of the bug?

@maskito/core, @maskito/kit

Playground Link

https://stackblitz.com/edit/xd2ihb?file=index.ts&hideExplorer=1

Description

When using date range mask and typing first symbol in input - it emits InputEvent twice, check out stackblitz, type for ex. 1 in input and check console logs. I guess assigning placeholder firstly and actual 1D/MM/YYYY - DD/MM/YYYY after causing this issue. Can maskito handle this?

Maskito version

1.9.0

Which browsers have you used?

Which operating systems have you used?

nsbarsukov commented 9 months ago

User types the first digit => 1st input event.

Maskito add placeholder => Maskito programatically update textfield' value => 2nd input event.

It is important to dispatch input-event for programatic updates of textfield (the such popular frameworks like React and Angular require it to update internal states of their components).

ko1ebayev commented 9 months ago

I did not use any framework-specific packages in my example, with plain TS and HTML event fires twice too. You can't catch keypress event, validate it and patch control with masked value?

nsbarsukov commented 9 months ago

I did not use any framework-specific packages in my example, with plain TS and HTML event fires twice too. You can't catch keypress event, validate it and patch control with masked value?

We use only beforeinput & input events for Maskito.

nsbarsukov commented 9 months ago

My mistake, I think i have idea how to remove some excess dispatchings of input-event

ko1ebayev commented 9 months ago

Thank you very much for deciding to work on this case!

nsbarsukov commented 9 months ago

@ko1ebayev

This bugfix will be released in Maskito 2.0.0 (the expected release date is the second half of January)