Open pritamaims360 opened 1 week ago
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.
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
Environment react-to-print version: 2.14.7 React version: 17.0.1 Browser: Version 130.0.6723.92 (Official Build) (64-bit)