Search code examples
reactjsoffice-jsoffice-addinsexcel-addins

How to create a confirm dialog with office-js and react?


I'd like to write a simple confirm modal for my office excel addin written in React.

This doesn't work because window.confirm has been forbidden by officejs (cf this explanation).

onClick={() => { if (window.confirm('Are you sure you wish to delete this item?')) { this.handleClick(); } }}>

According to officeJS doc, I could use the dialog api but those dialogs are not modals, therefore don't match my usecase : I want the user to confirm the action before going further.

Is there another way ?

Thanks


Solution

  • There's a modal Fabric React dialog component. From what you say about your use case, it might be what you are looking for. The reference for it is here: Dialog component in Fabric React.