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] - Modal onOpenChange only fires on close #3887

Open
Twansparant opened this issue Oct 14, 2024 · 3 comments · May be fixed by #3902
Open

[BUG] - Modal onOpenChange only fires on close #3887

Twansparant opened this issue Oct 14, 2024 · 3 comments · May be fixed by #3902
Assignees
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working

Comments

@Twansparant
Copy link

Twansparant commented Oct 14, 2024

NextUI Version

2.4.8

Describe the bug

I'm trying to (lazy) load a video in a nextui modal when it opens and pause it when it closes.
When I use the most basic modal example I can find, the onOpenChange event only fires when the modal closes.

Your Example Website or App

CodeSandbox

Steps to Reproduce the Bug or Issue

When running the most basic example, you will see the onOpenChange only fires when closing the modal:

import {Modal, ModalContent, ModalHeader, ModalBody, ModalFooter, Button, useDisclosure} from "@nextui-org/react";

export default function App() {
  const {isOpen, onOpen, onOpenChange} = useDisclosure();

  return (
    <>
      <Button onPress={onOpen}>Open Modal</Button>
      <Modal
            isOpen={isOpen}
            onOpenChange={isOpen => {
                  console.log(isOpen) // only fires on close
                  onOpenChange()
            }}
      >
        <ModalContent>
          {(onClose) => (
            <>
              <ModalHeader className="flex flex-col gap-1">Modal Title</ModalHeader>
              <ModalBody>
                <p> 
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                  Nullam pulvinar risus non risus hendrerit venenatis.
                  Pellentesque sit amet hendrerit risus, sed porttitor quam.
                </p>
                <p>
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                  Nullam pulvinar risus non risus hendrerit venenatis.
                  Pellentesque sit amet hendrerit risus, sed porttitor quam.
                </p>
                <p>
                  Magna exercitation reprehenderit magna aute tempor cupidatat consequat elit
                  dolor adipisicing. Mollit dolor eiusmod sunt ex incididunt cillum quis. 
                  Velit duis sit officia eiusmod Lorem aliqua enim laboris do dolor eiusmod. 
                  Et mollit incididunt nisi consectetur esse laborum eiusmod pariatur 
                  proident Lorem eiusmod et. Culpa deserunt nostrud ad veniam.
                </p>
              </ModalBody>
              <ModalFooter>
                <Button color="danger" variant="light" onPress={onClose}>
                  Close
                </Button>
                <Button color="primary" onPress={onClose}>
                  Action
                </Button>
              </ModalFooter>
            </>
          )}
        </ModalContent>
      </Modal>
    </>
  );
}

Expected behavior

I would expect the onOpenChange would also fire when the modal is fully opened and all content is loaded, but it does not?

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

Copy link

linear bot commented Oct 14, 2024

@sanuj21
Copy link
Contributor

sanuj21 commented Oct 14, 2024

@wingkwong can i work on this ?

@wingkwong wingkwong added 🐛 Type: Bug Something isn't working 📦 Scope : Components Related to the components labels Oct 14, 2024
@sanuj21 sanuj21 linked a pull request Oct 16, 2024 that will close this issue
@ryo-manba
Copy link
Member

As a temporary workaround, you can pass onChange to useDisclosure to handle this.

const { isOpen, onOpen, onOpenChange } = useDisclosure({
    onChange: console.log,
})

See: #3902 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 Scope : Components Related to the components 🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants