daisyui / react-daisyui

daisyUI components built with React 🌼
http://react.daisyui.com/
MIT License
961 stars 103 forks source link

[Help] Any simple way of closing dropdow on click? #275

Closed AlexandreRoba closed 1 year ago

AlexandreRoba commented 1 year ago

Hi all,

This is my code. i've been working 2 hours on trying to find a way to close the dropdown on click... How can I achieve this?

There is an open attribute...How do I get the reference to it on the handler? I tried using useRef() whitout any success. i cannot find the proper type... :(

const handleOnClick = (l: string) => {
    router.push({ pathname, query }, asPath, { locale: l });
  };

  return (
    <Dropdown>
      <Dropdown.Toggle color="ghost">{locale.toUpperCase()} </Dropdown.Toggle>
      <Dropdown.Menu>
        {locales.map((l) =>
          <Dropdown.Item key={l} onClick={() => handleOnClick(l)}>{l?.toUpperCase()}</Dropdown.Item>
        )}
      </Dropdown.Menu>
    </Dropdown>
benjitrosch commented 1 year ago

Hi @AlexandreRoba, see this thread for a few different ways to do this:

https://github.com/saadeghi/daisyui/issues/157