Focus the Delete Button in a Confirm Dialog
To focus the delete button, instead of the cancel button, when opening the delete annotation dialog, register an annotations.willChange
event listener:
instance.addEventListener("annotations.willChange", (event) => { const annotation = event.annotations.get(0); if ( event.reason === PSPDFKit.AnnotationsWillChangeReason.DELETE_START ) { console.log("Will open deletion confirmation dialog"); // We need to wrap the logic in a `setTimeOut()`, because the modal will be rendered on the next tick. setTimeout(function () { // The button is in the context of the PSPDFKit iframe. const button = instance.contentDocument.getElementsByClassName( "PSPDFKit-Confirm-Dialog-Button-Confirm" )[0]; button.focus(); }, 0); } });
This has been tested with PSPDFKit for Web 2020.6.1.