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

[BUG] - Button onPress event flaky in modal #4451

Open
coratgerl opened this issue Dec 26, 2024 · 6 comments
Open

[BUG] - Button onPress event flaky in modal #4451

coratgerl opened this issue Dec 26, 2024 · 6 comments

Comments

@coratgerl
Copy link

NextUI Version

2.6.8

Describe the bug

I have a modal with a button to submit a form inside the modal. On a playwright test the event onPress is not trigger if I don't wait 500 ms before click on button. This work with onClick event. There is no state update on my side that can flaky my code. My test also check that my button is enabled before click and this step works.

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

Not sure how to reproduce because it is very specific on this modal, but my modal look like this :

 <Modal
    isOpen={isOpen}
    onOpenChange={(open) => {
      if (!open) onClose()
    }}
  >
    <ModalContent>
      {(onClose) => (
        <>
          <ModalHeader className="flex flex-col gap-1">
            Create
          </ModalHeader>

          <ModalBody>
              <Input
                name="maxRedemptions"
                onBlur={form.handleBlur}
                onChange={form.handleChange}
                type="text"
                variant="faded"
                label="Max usages"
                errorMessage={form.errors.maxRedemptions}
                value={form.values.maxRedemptions}
                isInvalid={
                  form.dirty &&
                  form.touched.maxRedemptions &&
                  !!form.errors.maxRedemptions
                }
              />
          </ModalBody>

          <ModalFooter>
            <Button
              color="default"
              variant="light"
              onPress={onClose}
              className="Cancel"
            >
              Cancel
            </Button>

            <Button
              // OnPress is flaky here
              onPress={() => {
                   console.log("onPress") // Never display on click
                   return form.handleSubmit()
              }}
              isDisabled={!form.isValid}
              isLoading={form.isSubmitting}
              className="SubmitCreatePromotion"
            >
              Create
            </Button>
          </ModalFooter>
        </>
      )}
    </ModalContent>
  </Modal>

Expected behavior

The onPress is call

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

Copy link

linear bot commented Dec 26, 2024

@coratgerl coratgerl changed the title [BUG] - Button onPress event flaky in modal [BUG] - Button onPress event flaky in modal Dec 26, 2024
@AnYiEE
Copy link
Contributor

AnYiEE commented Dec 27, 2024

Because of this issue, as well as another problem I encountered in a newer version, I fixed the version used in my production environment to 2.6.5. Apart from a minor issue with the Popover-based animation, I haven't received any other error reports.

In version 2.6.5, I can use onClick. I'm not that focused on accessibility; instead, I prefer the elements on the page to respond correctly to most people's interactions.

Also report in #4322 (comment) .

@wingkwong wingkwong added 🐛 Type: Bug Something isn't working and removed Bug labels Dec 27, 2024
@coratgerl
Copy link
Author

coratgerl commented Dec 30, 2024

With the latest version and the deprecation in more components, I have a lot of test that not pass now with onPress. Mainly on submit button in modal.

@Peterl561
Copy link
Contributor

Please provide a minimal sandbox for your modal setup with the flaky test result.

@keul
Copy link

keul commented Jan 9, 2025

@coratgerl not 100% sure is the same issue, but I identified a very similar problem using Button inside forms after migrating to 2.6.10 (also tested 2.6.11).

Here a reproducible example: https://codesandbox.io/p/sandbox/qzmwk4?file=%2Fsrc%2FApp.tsx

Using the Button with onPress makes the form to be submitted

@coratgerl
Copy link
Author

I am not sure that is the same issue, because in my case the form is never submitted, but interesting ! I try to create a minimal sandbox but it is hard because I have a complex environnement for my tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants