Git Product home page Git Product logo

Comments (4)

Arttse avatar Arttse commented on May 27, 2024 1

Maybe it's not a bug, but a feature. It's just that it wasn't described properly and that's why it's confusing to others.

In v4, now you need to manage the closing of dropdown yourself. Like that:

import { useState } from "react";
import Dropdown from "rc-dropdown";
import type { DropdownProps } from "rc-dropdown/lib/Dropdown";
import Menu, { MenuItem, Divider, MenuProps } from "rc-menu";
import "rc-dropdown/assets/index.css";
import "rc-menu/assets/index.css";

export default function App() {
  const [visible, setVisible] = useState(false);

  const onSelect: Required<MenuProps>["onSelect"] = ({ key }) => {
    console.log(`${key} selected`);
    // here close dropdown on select menu item
    setVisible(false);
  };

  const onVisibleChange: Required<DropdownProps>["onVisibleChange"] = (
    visible
  ) => {
    console.log("visible", visible);
    setVisible(visible);
  };

  const menuCallback = () => (
    <Menu onSelect={onSelect}>
      <MenuItem disabled>disabled</MenuItem>
      <MenuItem key="1">one</MenuItem>
      <Divider />
      <MenuItem key="2">two</MenuItem>
    </Menu>
  );

  return (
    <Dropdown
      trigger={["click"]}
      overlay={menuCallback}
      animation="slide-up"
      // controlled
      visible={visible}
      onVisibleChange={onVisibleChange}
    >
      <button style={{ width: 100 }}>open</button>
    </Dropdown>
  );
}

Now you can control at what action to close dropdown with any overlay. Therefore, I close the issue.

from dropdown.

Arttse avatar Arttse commented on May 27, 2024

I also found that the examples use old version of rc-dropdown. Example https://dropdown-react-component.vercel.app/?path=/story/rc-dropdown--simple

from dropdown.

afc163 avatar afc163 commented on May 27, 2024

PR welcome~

from dropdown.

ismajl-ramadani avatar ismajl-ramadani commented on May 27, 2024

PR welcome~

I would do a PR, but can you share any thought on how to implement this properly? I'm thinking to pass a prop that is a flag for the onClick event. I see that onPopupClick of Trigger calls onClick handler, and then setTriggerVisible(false); is called immediately, and by passing that prop It would stop that call, hence the dropdown will retain its state.

from dropdown.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.