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

feat: added modal.onMounted handler #1082

Merged
merged 1 commit into from
May 2, 2024
Merged

feat: added modal.onMounted handler #1082

merged 1 commit into from
May 2, 2024

Conversation

bang9
Copy link
Contributor

@bang9 bang9 commented Apr 30, 2024

  • Added modal.onMounted handler to global eventHandlers.
    This event handler is triggered within the useEffect of the Modal component at mounting time.

Example usage

const App = () => {
  return (
    <SendbirdProvider
      eventHandlers={{
        modal: {
          onMounted({ id, close }) {
            // Push the state to prevent the browser's back button press
            window.history.pushState({ id }, '');

            // Close the modal if the back button is pressed
            const onPopState = (e: PopStateEvent) => {
              e.preventDefault(); // Prevents the default back action
              close(); // Closes the modal
            };
            window.addEventListener('popstate', onPopState);

            // Cleanup function
            return () => {
              // Clear the current state when the modal is closed without using the back button
              if (window.history.state?.id === id) window.history.back();
              window.removeEventListener('popstate', onPopState);
            };
          }
        }
      }}
    />
  );
};

ticket: CLNP-3057

@bang9 bang9 self-assigned this Apr 30, 2024
Copy link

netlify bot commented Apr 30, 2024

Deploy Preview for sendbird-uikit-react ready!

Name Link
🔨 Latest commit 3464a47
🔍 Latest deploy log https://app.netlify.com/sites/sendbird-uikit-react/deploys/66308646b1502900081cc102
😎 Deploy Preview https://deploy-preview-1082--sendbird-uikit-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@HoonBaek HoonBaek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bang9 bang9 merged commit 8681b0d into main May 2, 2024
8 checks passed
@bang9 bang9 added the v3.14.4 label May 2, 2024
@HoonBaek HoonBaek deleted the feat/modal-mount-handler branch May 2, 2024 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants