下拉菜单未显示在我的React Hooks中,在主页中导入的Navbar组件中。

huangapple go评论83阅读模式
英文:

Dropdown menu is not displaying in my react hooks in a Navbar component imported in Home page

问题

在我的导航栏中,"About Us" 下拉菜单在我的React Hooks Web应用程序中未显示。以下是我安装的依赖项。请问可能的原因是什么?

CSB链接:https://codesandbox.io/s/elegant-solomon-s7hyck?file=/public/index.html:571-622

"flowbite": "^1.7.0",
"flowbite-react": "^0.4.11",
"postcss": "^8.4.25",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"tailwindcss": "^3.3.2"

导航栏组件:

const Navbar = () => {
    return (
        <nav className="bg-white border-gray-200 dark:bg-gray-900 dark:border-gray-700">
            <div className="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
                <a href="#" className="flex items-center">
                    <img src="https://flowbite.com/docs/images/logo.svg" className="h-8 mr-3" alt="Flowbite Logo" />
                    <span className="self-center text-2xl font-semibold whitespace-nowrap dark:text-white">Flowbite</span>
                </a>
                <button data-collapse-toggle="navbar-dropdown" type="button" className="inline-flex items-center p-2 w-10 h-10 justify-center text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600" aria-controls="navbar-dropdown" aria-expanded="false">
                    <span className="sr-only">Open main menu</span>
                    <svg className="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14">
                        <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h15M1 7h15M1 13h15" />
                    </svg>
                </button>
                <div className="hidden w-full md:block md:w-auto" id="navbar-dropdown">
                    <ul className="flex flex-col font-medium p-4 md:p-0 mt-4 border border-gray-100 rounded-lg bg-gray-50 md:flex-row md:space-x-8 md:mt-0 md:border-0 md:bg-white dark:bg-gray-800 md:dark:bg-gray-900 dark:border-gray-700">
                        <li>
                            <a href="#" className="block py-2 pl-3 pr-4 text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 md:p-0 md:dark:text-blue-500 dark:bg-blue-600 md:dark:bg-transparent" aria-current="page">Home</a>
                        </li>
                        <li>
                            <button id="dropdownNavbarLink" data-dropdown-toggle="dropdownNavbar" className="flex items-center justify-between w-full py-2 pl-3 pr-4 text-gray-900 rounded hover-bg-gray-100 md:hover-bg-transparent md:border-0 md:hover-text-blue-700 md:p-0 md:w-auto dark:text-white md:dark:hover-text-blue-500 dark:focus-text-white dark:border-gray-700 dark:hover-bg-gray-700 md:dark:hover-bg-transparent">About Us <svg className="w-2.5 h-2.5 ml-2.5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 10 6"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 4 4 4-4" /></svg></button>
                            <div id="dropdownNavbar" className="z-10 hidden font-normal bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700 dark:divide-gray-600">
                                <ul className="py-2 text-sm text-gray-700 dark:text-gray-400" aria-labelledby="dropdownLargeButton">
                                    <li>
                                        <a href="https://flowbite.com/" className="block px-4 py-2 hover-bg-gray-100 dark:hover-bg-gray-600 dark:hover-text-white">About Rob NDIS</a>
                                    </li>
                                    <li>
                                        <a href="#" className="block px-4 py-2 hover-bg-gray-100 dark:hover-bg-gray-600 dark:hover-text-white">Our People</a>
                                    </li>
                                    <li>
                                        <a href="#" className="block px-4 py-2 hover-bg-gray-100 dark:hover-bg-gray-600 dark:hover-text-white">Mission Statment</a>
                                    </li>
                                </ul>
                                <div className="py-1">
                                    <a href="#" className="block px-4 py-2 text-sm text-gray-700 hover-bg-gray-100 dark:hover-bg-gray-600 dark:text-gray-400 dark:hover-text-white">Sign out</a>
                                </div>
                            </div>
                        </li>
                        <li>
                            <a href="#" className="block py-2 pl-3 pr-4 text-gray-900 rounded hover-bg-gray-100 md:hover-bg-transparent md:border-0 md:hover-text-blue-700 md:p-0 dark:text-white md:dark:hover-text-blue-500 dark:hover-bg-gray-700 dark:hover-text-white md:dark:hover-bg-transparent">Services</a>
                        </li>
                        <li>
                            <a href="#" className="block py-2 pl-3 pr-4 text-gray-900 rounded hover-bg-gray-100 md:hover-bg-transparent md:border-0 md:hover-text-blue-700 md:p-0 dark:text-white md:dark:hover-text-blue-500 dark:hover-bg-gray-700 dark:hover-text-white md:dark:hover-bg-transparent">Contact</a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    );
};

export default Navbar;

Tailwind配置:

module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}"
  ],
  theme: {
    extend: {},
  },
  plugins: [require('flowbite/plugin')],
}

Home.js:

import React from 'react';
import Navbar from './Navbar';

const Home = () => {
  return (
    <div className='container'>
      <Navbar/>
      <div className="container mx-auto bg-gray-200 rounded-xl shadow border p-8 m-10">
        <h1 className="text-2xl font-bold text-center">Welcome to the "Rob NDIS"</h1>
        <p className="text-3xl text-gray-700 font-bold mb-5">
            Welcome!
        </p>
        <p className="text-gray-500 text-lg">
            React and Tailwind CSS in action
        </p>
      </div>
    </div>
 

<details>
<summary>英文:</summary>

In my Navbar, the `About Us` dropdown menu is not displaying in my react hooks web app. Following are my dependencies installed. Could someone please advise what could be the reason here ? 

CSB link: https://codesandbox.io/s/elegant-solomon-s7hyck?file=/public/index.html:571-622

[![enter image description here][1]][1]

    &quot;flowbite&quot;: &quot;^1.7.0&quot;,
    &quot;flowbite-react&quot;: &quot;^0.4.11&quot;,
    &quot;postcss&quot;: &quot;^8.4.25&quot;,
    &quot;react&quot;: &quot;^18.2.0&quot;,
    &quot;react-dom&quot;: &quot;^18.2.0&quot;,
    &quot;react-scripts&quot;: &quot;5.0.1&quot;,
    &quot;tailwindcss&quot;: &quot;^3.3.2&quot;
// Navbar component:

    const Navbar = () =&gt; {
        return (
            &lt;nav className=&quot;bg-white border-gray-200 dark:bg-gray-900 dark:border-gray-700&quot;&gt;
                &lt;div className=&quot;max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4&quot;&gt;
                    &lt;a href=&quot;#&quot; className=&quot;flex items-center&quot;&gt;
                        &lt;img src=&quot;https://flowbite.com/docs/images/logo.svg&quot; className=&quot;h-8 mr-3&quot; alt=&quot;Flowbite Logo&quot; /&gt;
                        &lt;span className=&quot;self-center text-2xl font-semibold whitespace-nowrap dark:text-white&quot;&gt;Flowbite&lt;/span&gt;
                    &lt;/a&gt;
                    &lt;button data-collapse-toggle=&quot;navbar-dropdown&quot; type=&quot;button&quot; className=&quot;inline-flex items-center p-2 w-10 h-10 justify-center text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600&quot; aria-controls=&quot;navbar-dropdown&quot; aria-expanded=&quot;false&quot;&gt;
                        &lt;span className=&quot;sr-only&quot;&gt;Open main menu&lt;/span&gt;
                        &lt;svg className=&quot;w-5 h-5&quot; aria-hidden=&quot;true&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; fill=&quot;none&quot; viewBox=&quot;0 0 17 14&quot;&gt;
                            &lt;path stroke=&quot;currentColor&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; stroke-width=&quot;2&quot; d=&quot;M1 1h15M1 7h15M1 13h15&quot; /&gt;
                        &lt;/svg&gt;
                    &lt;/button&gt;
                    &lt;div className=&quot;hidden w-full md:block md:w-auto&quot; id=&quot;navbar-dropdown&quot;&gt;
                        &lt;ul className=&quot;flex flex-col font-medium p-4 md:p-0 mt-4 border border-gray-100 rounded-lg bg-gray-50 md:flex-row md:space-x-8 md:mt-0 md:border-0 md:bg-white dark:bg-gray-800 md:dark:bg-gray-900 dark:border-gray-700&quot;&gt;
                            &lt;li&gt;
                                &lt;a href=&quot;#&quot; className=&quot;block py-2 pl-3 pr-4 text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 md:p-0 md:dark:text-blue-500 dark:bg-blue-600 md:dark:bg-transparent&quot; aria-current=&quot;page&quot;&gt;Home&lt;/a&gt;
                            &lt;/li&gt;
                            &lt;li&gt;
                                &lt;button id=&quot;dropdownNavbarLink&quot; data-dropdown-toggle=&quot;dropdownNavbar&quot; className=&quot;flex items-center justify-between w-full py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 md:w-auto dark:text-white md:dark:hover:text-blue-500 dark:focus:text-white dark:border-gray-700 dark:hover:bg-gray-700 md:dark:hover:bg-transparent&quot;&gt;About Us &lt;svg className=&quot;w-2.5 h-2.5 ml-2.5&quot; aria-hidden=&quot;true&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; fill=&quot;none&quot; viewBox=&quot;0 0 10 6&quot;&gt;
                                    &lt;path stroke=&quot;currentColor&quot; stroke-linecap=&quot;round&quot; stroke-linejoin=&quot;round&quot; stroke-width=&quot;2&quot; d=&quot;m1 1 4 4 4-4&quot; /&gt;
                                &lt;/svg&gt;&lt;/button&gt;
    
                                &lt;div id=&quot;dropdownNavbar&quot; className=&quot;z-10 hidden font-normal bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700 dark:divide-gray-600&quot;&gt;
                                    &lt;ul className=&quot;py-2 text-sm text-gray-700 dark:text-gray-400&quot; aria-labelledby=&quot;dropdownLargeButton&quot;&gt;
                                        &lt;li&gt;
                                            &lt;a href=&quot;https://flowbite.com/&quot; className=&quot;block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white&quot;&gt;About Rob NDIS&lt;/a&gt;
                                        &lt;/li&gt;
                                        &lt;li&gt;
                                            &lt;a href=&quot;#&quot; className=&quot;block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white&quot;&gt;Our People&lt;/a&gt;
                                        &lt;/li&gt;
                                        &lt;li&gt;
                                            &lt;a href=&quot;#&quot; className=&quot;block px-4 py-2 hover:bg-gray-100 dark:hover:bg-gray-600 dark:hover:text-white&quot;&gt;Mission Statment&lt;/a&gt;
                                        &lt;/li&gt;
                                    &lt;/ul&gt;
                                    &lt;div className=&quot;py-1&quot;&gt;
                                        &lt;a href=&quot;#&quot; className=&quot;block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-400 dark:hover:text-white&quot;&gt;Sign out&lt;/a&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                            &lt;/li&gt;
                            &lt;li&gt;
                                &lt;a href=&quot;#&quot; className=&quot;block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent&quot;&gt;Services&lt;/a&gt;
                            &lt;/li&gt;
            &lt;li&gt;
              &lt;a href=&quot;#&quot; className=&quot;block py-2 pl-3 pr-4 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent&quot;&gt;Contact&lt;/a&gt;
            &lt;/li&gt;
                        &lt;/ul&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/nav&gt;
    
        );
    };
    
    export default Navbar;
  
Tailwind Configuration: 

    /** @type {import(&#39;tailwindcss&#39;).Config} */
    module.exports = {
      content: [
        &quot;./src/**/*.{js,jsx,ts,tsx}&quot;
      ],
      theme: {
        extend: {},
      },
      plugins: [require(&#39;flowbite/plugin&#39;)
      ],
    }

// Home.js

    import React from &#39;react&#39;;
    import Navbar from &#39;./Navbar&#39;;
    
    const Home = () =&gt; {
      return (
    
         &lt;div className=&#39;container&#39;&gt;
            &lt;Navbar/&gt;
            &lt;div className=&quot;container mx-auto bg-gray-200 rounded-xl shadow border p-8 m-10&quot;&gt;
              &lt;h1 className=&quot;text-2xl font-bold text-center&quot;&gt;Welcome to the &quot;Rob NDIS&quot;&lt;/h1&gt;
              &lt;p className=&quot;text-3xl text-gray-700 font-bold mb-5&quot;&gt;
                  Welcome!
              &lt;/p&gt;
              &lt;p className=&quot;text-gray-500 text-lg&quot;&gt;
                  React and Tailwind CSS in action
              &lt;/p&gt;
          &lt;/div&gt; 
    
         &lt;/div&gt;
          
        
      );
    };
    
    export default Home;

[![enter image description here][2]][2]


  [1]: https://i.stack.imgur.com/b427k.png


</details>


# 答案1
**得分**: 2

"the dropdown menu is not displaying because of this hidden property in this line."
"这个下拉菜单没有显示是因为这行代码中有一个隐藏属性。"

"you should handle it when the user clicks, hover or etc on it you should show it in one of these modes."
"当用户点击、悬停等操作时,你应该处理它,以在其中一种模式下显示它。"

"for more example, you can see: https://flowbite.com/docs/components/dropdowns/"
"如果需要更多示例,你可以查看:https://flowbite.com/docs/components/dropdowns/"

"good luck Dear."
"祝你好运,亲爱的。"

<details>
<summary>英文:</summary>

the dropdown menu is not displaying because of this hidden property in this line.
&quot; className=&quot;z-10 hidden flex focus:  font-normal bg-white divide-y divide-gray-100 rounded-lg shadow w-44 dark:bg-gray-700 dark:divide-gray-600&quot;&quot;.
you should handle it when the user clicks, hover or etc on it you should show it in one of these modes.
for more example, you can see: https://flowbite.com/docs/components/dropdowns/
good luck Dear.

</details>



huangapple
  • 本文由 发表于 2023年7月13日 10:14:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675486.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定