Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picker 选择器指令能否提供关闭所有打开的Picker #6471

Closed
Alibaba-Jarry opened this issue Dec 8, 2023 · 1 comment
Closed
Labels

Comments

@Alibaba-Jarry
Copy link

Version of antd-mobile

5.33.0

What is this feature about?

在使用指令式的Picker的时候,用户返回页面,Picker还是存在于当前页面,希望提供一个类似:‘’可以通过调用 Modal 上的 clear 方法关闭所有打开的弹窗,通常用于路由监听中,处理路由前进、后退不能关闭弹窗的问题。‘’

@zombieJ
Copy link
Member

zombieJ commented Dec 8, 2023

Picker 是通过 visible 受控控制,全局的控制方法不符合 React 的设计规范。但是如果业务里真的要这么搞,你可以 HOC 一下 Picker 组件,然后自行控制该逻辑:

const closeFnSet = new Set();

const MyPicker = (props) => {
  const [visible, setVisible] = useState(false);

  useEffect(() => {
    const onClose = () => setVisible(false);
    closeFnSet.add(closeFnList);

     return () => {
      closeFnSet.delete(closeFnSet);
    }
  }, []);

  return <Picker visible={visible} />
}

// 写个全局方法遍历 closeFnSet,调用删除

@zombieJ zombieJ closed this as completed Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants