为什么点击我的模态时,模型消失了

whay when clicking on my modal, the model disappears

请帮忙!为什么单击我的模态时,模型消失了。我希望仅当单击外部模式时。我需要更改 z-index 还是什么?请检查示例。

真正的关闭功能在上下文页面上,但它运行良好。 我尝试更改 z-index 但它仍然不起作用

export default class FeaturedPortfolio extends Component {
  static contextType = PortfolioContext;

  render() {
    let { loading, featuredPortfolio: portfolio } = this.context;
    portfolio = portfolio.map((portfolios) => {
      return <SinglePortfolio key={portfolios.id} portfolios={portfolios} />;
    });
    return (
      <PortfolioConsumer>
        {(value) => {
          const { modalPortfolioOpen } = value;
          if (!modalPortfolioOpen) {
            return null;
          } else {
            return (
              <motion.div
                initial="out"
                animate="in"
                exit="out"
                variants={pageVariant}
                transition={pageTransition}
              >
                <CloseSection
                  onClick={() => {
                    value.closePortfolioModal();
                  }}
                >
                  <Section>
                    <div className="row-title">
                      <Title title="portfolio" />
                    </div>
                    <ModalContainer>
                      <div className="featured-rooms-center">
                        {loading ? <Loading /> : portfolio}
                      </div>
                    </ModalContainer>

                    <button
                      className="btn-close"
                      onClick={() => {
                        value.closePortfolioModal();
                      }}
                    >
                      <i className="fas fa-times-circle" title="Close" />
                    </button>
                    <div className="button-row">
                      <Link to="/portfolios/">
                        <button className="btn-primary">See all</button>
                      </Link>
                    </div>
                  </Section>
                </CloseSection>
              </motion.div>
            );
          }
        }}
      </PortfolioConsumer>
    );
  }
}

const CloseSection = styled.div`
  color: rgba(2, 2, 34, 0.404);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  z-index: 1;
`;
const Section = styled.div`
  position: fixed;
  padding: 0 0;
  z-index: 2;
  width: 90%;
  height: 60%;
  left: 5%;
  right: 5%;
  position: absolute;
  top: 20%;
  bottom: 5%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--mainDark);
  box-shadow: 0 0 40px -10px var(--mainAccent);
  border-radius: 12px;
  .row-title {
    margin-top: 0.5rem;
    justify-content: center;
    position: absolute;
    top: 0;
  }

感谢您的帮助。

最后,为我的问题找到解决方案,所以如果在我的模态外单击时需要关闭模态,我只需要创建与模态内容分开的可能关闭部分并放置 lover z-index。

<CloseSection
onClick={() => {
value.closePortfolioModal();
}}
/>
  const CloseSection = styled.div`
  color: rgba(2, 2, 34, 0.404);
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  z-index: 1;
;`