reactjscarbon-design-system

How to close carbon Modal on save


I'm using ModalWrapper from 'carbon-components-react'

On clicking Save, it is not closing the modal. How to force it to close?

See example codesandbox https://codesandbox.io/s/carbon-components-react-forked-n09un?file=/src/index.js


Solution

  • Use ModalWrapper, you must add shouldCloseAfterSubmit to your ModalWrapper and return true in your handleModalSave function

    // HandleModalSave
    const handleModalSave = (data, ssdf) => {
      return true;
    };
    
    // ModalWrapper
    <ModalWrapper
      buttonTriggerText="Save"
      modalHeading="Save Table"
      handleSubmit={handleModalSave}
      primaryButtonText={primaryButtonText}
      shouldCloseAfterSubmit
    >