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

Unable to Detect Print Confirmation or Cancellation in react-to-print #763

Open
pritamaims360 opened this issue Nov 12, 2024 · 1 comment
Labels

Comments

@pritamaims360
Copy link

pritamaims360 commented Nov 12, 2024

Description

When using react-to-print to print content in a React application, the library provides hooks like onBeforePrint and onAfterPrint to manage actions before and after the print dialog appears. However, there is currently no reliable way to detect if the user actually confirms the print (i.e., completes printing) or cancels the print dialog.

This limitation makes it challenging to handle certain actions conditionally based on the print confirmation status, such as triggering an API call, logging, or updating a counter. onAfterPrint is always triggered regardless of whether the print dialog was confirmed or canceled, which leads to unwanted behavior when specific actions should only occur upon confirmed prints.

Expected Behavior:
The react-to-print library should provide a way to differentiate between a confirmed print and a canceled print. This could be achieved by adding a new callback (e.g., onPrintConfirmed) or by passing an argument to onAfterPrint indicating the print status.

Steps to Reproduce

  1. Set up react-to-print with onBeforePrint and onAfterPrint callbacks.
  2. Open the print dialog and either confirm or cancel the print.
  3. Observe that onAfterPrint is triggered in both cases, without a way to determine whether the print was completed or canceled.

Environment
react-to-print version: 2.14.7
React version: 17.0.1
Browser: Version 130.0.6723.92 (Official Build) (64-bit)

@MatthewHerbst
Copy link
Owner

MatthewHerbst commented Nov 12, 2024

Hello. Unfortunately this is an html spec / browser limitation, there's nothing we can do about it 😢 See the afterprint event which is what we hook into to detect the print preview dialog has closed. This is unfortunately part of the HTML spec (8.8.2 Printing). I've been slowly working on a proposal to improve that API, but that change, if accepted, will take years unfortunately.

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

No branches or pull requests

2 participants