Open KevinGuedes opened 1 month ago
@KevinGuedes Hello!
First, sorry for the delay in getting back to you. Thank you for reporting this issue and providing such detailed suggestions! The solutions you proposed are interesting and can work well to address the problem.
I particularly like Solution B because it initializes the maskedValue
more robustly, ensuring the input value remains consistent with the value prop from the start. This approach reduces dependency on external props throughout the component's lifecycle, making the component more predictable and less prone to errors.
(I believe) this solution will help prevent future issues related to the component's initial state, especially in more complex scenarios. But what do think? Do you agree with this point?
Also, if you would like to open a PR with this change, I would be happy to review it!
Thanks again for your contribution and the kind words! 😊
Cheers from Minas Gerais! 😎
Description
By default, Shadcn's Dialog component will focus on the first focusable element once it is opened. When the Currency Mask input is the first focusable element of the dialog, the
value
anddefaultValue
are both ignored:Cause
When
handleFocuns
is called, the value ofinput.targer.value
is0
Demo Component
Solutions
After debugging a little bit, i came up with two solutions
A - Change
handleFocus
Since the
event.target.value
inside this function is0
, maybe we could use the actualvalue
prop sent to the component. That said,handleFocus
could be something like:B - Update the initial value for
maskedValue
This solution consists in updating the initial
maskedValue
to something like:Let me know your thoughts here and maybe we can discuss more! Once we agree on a solution i can open a PR.
Comments
Greeting from Brazil Fortaleza-CE! Awesome package @leoreisdias! I've been looking for a currency input/mask, found many of them but honestly the best one is react-currency-mask, congrats for the project!