D
D
Durilka962022-04-09 16:47:32
JavaScript
Durilka96, 2022-04-09 16:47:32

Why does the dropdown list close after I click on the dropdown child element, how can I fix this?

There is a drop-down list, I open the list with a click, and then I want to select several combo boxes that have fallen out, but after I click on one combo box, the drop-down list immediately closes, how to make it close only when it is clicked on and / or it was possible to select several combo boxes ?
Dropdown code:

//раскрывающийся список с помощью функции
    const Dropdown = ({ text, children }) => {
        const [isOpen, setIsOpen] = useState(false);
        const toggleOpen = () => setIsOpen(isOpen => !isOpen);
        if (isOpen) {
            return (
                <div>
                    <button className="dropdown-btn-close" onClick={toggleOpen} >
                        {text}
                        <span className="fa-caret-down"></span>
                    </button>
                    {isOpen && <div>{children}</div>}
                </div>
            );
        }
        else {
            return (
                <div>
                    <button className="dropdown-btn-active" onClick={toggleOpen} >
                        {text}
                        <span className="fa-caret-down"></span>
                    </button>
                    {isOpen && <div>{children}</div>}
                </div>
            );
        }
    }

open and closed respectively
62518e4f9409f486193455.png
62518e7277968621354726.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-04-09
@Durilka96

https://codesandbox.io/s/qna-q-1137116-i809oq?file...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question