trigger icon indicating copy to clipboard operation
trigger copied to clipboard

The 'popupVisible' not work

Open TaurusWood opened this issue 2 years ago • 4 comments

I use 'popupVisible' and 'onPopupVisibleChange' with React.useState,but popup won't close once opened

import React, { useState } from "react";
import "antd/dist/antd.css";

import Trigger from "rc-trigger";
import { List, Button } from "antd";

import "./index.css";

const App = () => {
  const [visible, setVisible] = useState(false)

  console.log(`visible`, visible)

  return (
    <div className="wrapper">
      <Trigger
        popupVisible={visible}
        action={["click"]}
        // destroyPopupOnHide={true}
        popup={<span>popup</span>}
        popupAlign={{
          points: ['tl', 'tr'],
          // offset: [0, 3]
        }}
        onPopupVisibleChange={(a) => {
          console.log('a', a)
          setVisible(a);
        }}
      >
        <Button block >+++</Button>
      </Trigger>
    </div>
  );
};

export default App;

Edit 垂直菜单 - antd@4.23.0 (forked)

TaurusWood avatar Sep 08 '22 16:09 TaurusWood

Maybe the real reason is Do not call Hooks in class components. and rc-trigger is class component. https://reactjs.org/warnings/invalid-hook-call-warning.html#breaking-the-rules-of-hooks

Cuiyansong avatar Nov 09 '22 09:11 Cuiyansong

+1 the click event is not propagated to the child components if the trigger action is set to click: CodeSandbox-Example

molnarlaura avatar Nov 25 '22 12:11 molnarlaura

I add prop destroyTooltipOnHide={true} on another lib named rc-tooltip, and it can close finally.

In this lib, the prop named destroyPopupOnHide

shaunhurryup avatar Dec 19 '22 02:12 shaunhurryup

+1 I come across same bug after upgrade react from 16 to 18 , the rc-trigger can't close popup after the popupVisible is false. @zombieJ

<Trigger action={!disabled ? ['click'] : []} prefixCls={prefix} popup={<Popup {...props} onCancel={handleCancel} onConfirm={handleConfirm} />} popupVisible={disabled ? false : popupVisible} onPopupVisibleChange={setPopupVisible} popupStyle={{ position: 'absolute', zIndex: 1050 }} builtinPlacements={BUILT_IN_PLACEMENTS} popupPlacement="bottomLeft" popupTransitionName={popupTransitionName} getPopupContainer={getPopupContainer || getContextPopupContainer} > <Selector forwardRef={selectorRef} onRemove={handleItemRemove} onClear={handleClear} {...props} /> </Trigger>

SSSliangfeng avatar Aug 07 '23 06:08 SSSliangfeng