首页 > 解决方案 > 如何在保存时关闭碳模态

问题描述

我正在使用来自“carbon-components-react”的 ModalWrapper

单击保存时,它不会关闭模式。如何强制关闭?

请参阅示例代码框 https://codesandbox.io/s/carbon-components-react-forked-n09un?file=/src/index.js

标签: reactjscarbon-design-system

解决方案


使用ModalWrapper,您必须将shouldCloseAfterSubmit添加到您的 ModalWrapper 并在您的handleModalSave函数中返回 true

// HandleModalSave
const handleModalSave = (data, ssdf) => {
  return true;
};

// ModalWrapper
<ModalWrapper
  buttonTriggerText="Save"
  modalHeading="Save Table"
  handleSubmit={handleModalSave}
  primaryButtonText={primaryButtonText}
  shouldCloseAfterSubmit
>

推荐阅读