Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar: Changing Calendar input (with mask) clears the rest of the form's state #4030

Closed
freiguy1 opened this issue Feb 3, 2023 · 2 comments · Fixed by #4796
Closed

Calendar: Changing Calendar input (with mask) clears the rest of the form's state #4030

freiguy1 opened this issue Feb 3, 2023 · 2 comments · Fixed by #4796
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@freiguy1
Copy link

freiguy1 commented Feb 3, 2023

Describe the bug

Our users noticed when manually typing in a date in a Calendar input box, the rest of the state of the form gets cleared out.

For example, the codesandbox link has 2 inputs. One is text, and one is a Calendar. If you have some text in the InputText, then start typing in the Calendar, your InputText gets cleared out.

One thing to notice is all the inputs' states are wrapped in an object, rather than each being their own useState:
var [form, setForm] = useState({ text: "", date: undefined });

Another important note: This problem only manifests when using the mask attribute on the Calendar. If you remove mask this problem goes away and behavior is as expected.

Reproducer

https://codesandbox.io/s/calendar-mask-problem-qxungp?file=/src/index.js

PrimeReact version

8.7.3

React version

18.x

Language

ALL

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

Inside the codesandbox example:

  1. Simply type something into the first input text box
  2. Then tab or click into calendar input box
  3. Start typing a date by pressing a number (like 1)
  4. Notice the text you initially entered in first text box is deleted

Expected behavior

I expect the text in the InputText to not be deleted.

@freiguy1 freiguy1 added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Feb 3, 2023
@melloware
Copy link
Member

Similar mask related issues:

#3728

#3628

@cxo05
Copy link
Contributor

cxo05 commented Aug 16, 2023

Using

onChange={(e) => {
  setForm((prevState) => {
    return { ...prevState, date: e.value };
  });
}}

Instead of

onChange={(e) => {
  setForm({...form, date: e.value});
}}

in the calendar component has different behaviour even though they should be doing the same thing.

Issue seems to be related to how the mask changes the calendar's bindings (or doesn't)

cxo05 added a commit to cxo05/primereact that referenced this issue Aug 17, 2023
cxo05 added a commit to cxo05/primereact that referenced this issue Aug 17, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Aug 17, 2023
@melloware melloware added this to the 10.0.0 milestone Aug 17, 2023
melloware added a commit that referenced this issue Aug 17, 2023
… form's state (#4796)

* Fix bug causing swipe events to not work

* Add onChangeRef
Fixes #4030

* Add comment

Co-authored-by: Melloware <[email protected]>

---------

Co-authored-by: Melloware <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants