Topic: Nav bar in react.js buttons toggle enable/disabled

bgining2this free asked 1 year ago


Expected behavior Make click on navbar buttons to fire events, button in navbar enabled/disabled on users loggin

Actual behavior Copied a example, but dont know how to fire events on button click

Resources (screenshots, code snippets etc.)

import React from 'react';
import { useUser } from '@auth0/nextjs-auth0'
import Link from 'next/link'
import { useRouter } from 'next/router'
import {
    MDBContainer,
    MDBNavbar,
    MDBNavbarBrand,
    MDBNavbarToggler,
    MDBIcon,
    MDBNavbarNav,
    MDBNavbarItem,
    MDBNavbarLink,
MDBBtn,
MDBDropdown,
MDBDropdownToggle,
MDBDropdownMenu,
MDBDropdownItem,
MDBDropdownLink,
MDBCollapse,
MDBInput
} from 'mdb-react-ui-kit';

const Nav = () => {
    const {user, error, isLoading} = useUser()
    const {pathname} = useRouter()

return (
    <nav className="navbar navbar-expand-lg navbar-light bg-light">
        <!-- Container wrapper -->
        <div className="container-fluid">
            <!-- Toggle button -->
            <button
                className="navbar-toggler"
                type="button"
                data-mdb-toggle="collapse"
                data-mdb-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent"
                aria-expanded="false"
                aria-label="Toggle navigation"
            >
                <i className="fas fa-bars"></i>
            </button>

            <!-- Collapsible wrapper -->
            <div className="collapse navbar-collapse" id="navbarSupportedContent">
                <!-- Navbar brand -->
                <a className="navbar-brand mt-2 mt-lg-0" href="#">
                    <img
                        src="https://mdbcdn.b-cdn.net/img/logo/mdb-transaprent-noshadows.webp"
                        height="15"
                        alt="MDB Logo"
                        loading="lazy"
                    />
                </a>
                <!-- Left links -->
                <ul className="navbar-nav me-auto mb-2 mb-lg-0">
                    <li className="nav-item">
                        <a className="nav-link" href="#">Dashboard</a>
                    </li>
                    <li className="nav-item">
                        <a className="nav-link" href="#">Team</a>
                    </li>
                    <li className="nav-item">
                        <a className="nav-link" href="#">Projects</a>
                    </li>
                </ul>
                <!-- Left links -->
            </div>
            <!-- Collapsible wrapper -->

            <!-- Right elements -->
            <div className="d-flex align-items-center">
                <!-- Icon -->
                <a className="text-reset me-3" href="#">
                    <i className="fas fa-shopping-cart"></i>
                </a>

                <!-- Notifications -->
                <div className="dropdown">
                    <a
                        className="text-reset me-3 dropdown-toggle hidden-arrow"
                        href="#"
                        id="navbarDropdownMenuLink"
                        role="button"
                        data-mdb-toggle="dropdown"
                        aria-expanded="false"
                    >
                        <i className="fas fa-bell"></i>
                        <span className="badge rounded-pill badge-notification bg-danger">1</span>
                    </a>
                    <ul
                        className="dropdown-menu dropdown-menu-end"
                        aria-labelledby="navbarDropdownMenuLink"
                    >
                        <li>
                            <a className="dropdown-item" href="#">Some news</a>
                        </li>
                        <li>
                            <a className="dropdown-item" href="#">Another news</a>
                        </li>
                        <li>
                            <a className="dropdown-item" href="#">Something else here</a>
                        </li>
                    </ul>
                </div>
                <!-- Avatar -->
                <div className="dropdown">
                    <a
                        className="dropdown-toggle d-flex align-items-center hidden-arrow"
                        href="#"
                        id="navbarDropdownMenuAvatar"
                        role="button"
                        data-mdb-toggle="dropdown"
                        aria-expanded="false"
                    >
                        <img
                            src="https://mdbcdn.b-cdn.net/img/new/avatars/2.webp"
                            className="rounded-circle"
                            height="25"
                            alt="Black and White Portrait of a Man"
                            loading="lazy"
                        />
                    </a>
                    <ul
                        className="dropdown-menu dropdown-menu-end"
                        aria-labelledby="navbarDropdownMenuAvatar"
                    >
                        <li>
                            <a className="dropdown-item" href="#">My profile</a>
                        </li>
                        <li>
                            <a className="dropdown-item" href="#">Settings</a>
                        </li>
                        <li>
                            <a className="dropdown-item" href="#">Logout</a>
                        </li>
                    </ul>
                </div>
            </div>
            <!-- Right elements -->
        </div>
        <!-- Container wrapper -->
    </nav>
)
}

bgining2this free commented 1 year ago

I only want 3 buttons the cart icon, the account circle icon, if i only knew how to add onclick events in buttons and enable/disable buttons UPDATE: now i have added all functionality to navbar but cart and bell icons are not shown


Krzysztof Wilk staff answered 1 year ago


Hi!

You copied the example from the MDB5 Standard documentation page, that's why your components don't work. For proper MDB5 React UI KIT usage you can check examples on our dedicated page - https://mdbootstrap.com/docs/b5/react/navigation/navbar/ :)

Keep coding!


bgining2this free commented 1 year ago

Thank you !!! @Krzysztof Wilk Have a nice day !!! Yes, code, then exist LOL


Krzysztof Wilk staff commented 1 year ago

I'm glad I could help. If you have more questions - feel free to ask :)



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 4.0.0
  • Device: Desktop
  • Browser: Chromium
  • OS: Linux
  • Provided sample code: No
  • Provided link: No