【问题标题】:Ionic popover with React - How to make it sticky to the button带有 React 的 Ionic popover - 如何使其粘在按钮上
【发布时间】:2020-04-29 15:28:21
【问题描述】:

按照 Ionic 文档,我试图让弹出框粘在按钮上 (like on their own example)。 不幸的是,我不知道如何实现这一目标...... 谢谢

import React, { useState } from 'react';
import { IonPopover, IonButton } from '@ionic/react';

export const PopoverExample: React.FC = () => {
  const [showPopover, setShowPopover] = useState(false);

  return (
    <>
      <IonPopover
        isOpen={showPopover}
        onDidDismiss={e => setShowPopover(false)}
      >
        <p>This is popover content</p>
      </IonPopover>
      <IonButton onClick={() => setShowPopover(true)}>Show Popover</IonButton>
    </>
  );
};

【问题讨论】:

    标签: reactjs ionic-framework


    【解决方案1】:

    您还需要在 showPopover 挂钩中包含一个事件 -

    const [showPopover, setShowPopover] = useState<{open: boolean, event: Event | undefined}>({
      open: false,
      event: undefined,
    });
    
    <IonPopover
        isOpen={showPopover.open}
        event={showPopover.event}
        onDidDismiss={e => setShowPopover({open: false, event: undefined})}
    >
       <p>This is popover content</p>
    </IonPopover>
    <IonButton onClick={(e) => setShowPopover({open: true, event: e.nativeEvent})}>Click</IonButton>
    

    【讨论】:

    • 不用担心,很高兴为您提供帮助:)
    • 如果对您有帮助,您能帮我一个忙并将其标记为答案吗?谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-07-06
    • 2020-10-23
    • 1970-01-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-10-23
    相关资源
    最近更新 更多