Is there a way to customize the default settings for a blueprint’s menu item?

https://i.sstatic.net/aNeJY.jpg

In my react project, I implemented the Menu using MenuItem from '@blueprintjs/core'. The issue I encountered is that when hovering over a Menu item with children, they open from the right side. Is there a way to modify this behavior and have the child submenu open below its parent item instead?

import React from 'react';
import { MenuItem } from '@blueprintjs/core';
import Style from './styled';

const leftMenu = () => {

const Items = createNav.map(menuItem => {
    let children;
    if ('children' in menuItem) {
        children = menuItem.children.map(child => {
            return (
                <MenuItem
                    icon={child.icon}
                    text={child.title}
                    href={child.path}
                    key={menuItem.path}
                    />
                );
            });
        }
        return (
            <Style.MenuItem
                icon={menuItem.icon}
                text={menuItem.title}
                href={menuItem.path}
                key={menuItem.path}
            >
                {children}
            </Style.MenuItem>
        );
    });
    return <Style.Menu>{Items}</Style.Menu>;
};

export default LeftMenu;

I utilized styled-components for styling purposes.

 const Menu = styled(bpMenu)`
     padding: 0 !important;
     background-color: transparent !important;
`;

const MenuItem = styled(Item)`
     background-color: red ;
     margin: 5px;
`;

Answer №1

Why is it opening automatically? I encountered an issue where the submenus were appearing on their own without any hover or click actions!

To fix this, I included autoFocus={false} in popover2. Check out my code snippet below:

<Popover2
     content={
       <>
        <Menu key="menu">
          <MenuItem icon="camera" text="Menu 1"></MenuItem>
          <MenuItem icon="dollar" text="Menu 2" disabled={true} />
          <MenuItem  icon="lifesaver" text="Football">
               <MenuItem icon="chart" text="Team 1" />
               <MenuItem icon="chart" text="Team 2" />
               <MenuItem icon="chart" text="Team 3" />
         </MenuItem>                                        
       </Menu>
      </>
     }
     position="bottom"
     interactionKind="hover"
     autoFocus={false}
>
     <Button
         text="vivid..."
         minimal
         large={false}
         className="b f5 white _btn_"
         intent="none"
         icon="share"
     />
</Popover2>

If you're looking for navBar styling, you can refer to the navBar documentation on blueprintjs website.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Finding the data type based on the button clicked with javascript: A beginner's guide

I am trying to work with a PHP function that generates dynamically created divisions. Each of these divisions contains a different data type and a button. How can I extract the data type of a division when the user clicks on the submit button using JavaScr ...

Is there a way to include an edit, delete, details, and create new icon in an @html.actionLink within MVC?

This HTML code is specific to MVC and represents the formatting used: 1. @*@Html.ActionLink("Delete", "Delete", new { id=item.ActivityDepreciationTypeId })*@ 2. @*@Html.ActionLink("Details", "Details", new { id=item.ActivityDepreciationTypeId })*@ ...

Using a powerful combination of Django, Django Rest Framework, and React (with TypeScript), I have created a React-Image component that beautifully displays my images in a 1295x

In my Django project, I have a hierarchy of Group, Class, Model, and Product models. These are structured in a Group{Class{Model{Product}}} format. To display this data, I created dropdown menus that function as follows: Group Checkbox |-Inner Classes ...

Utilizing the map() function to iterate through a list of outcomes and assigning the resulting array as the state of a component in ReactJS

Currently, I am facing an issue with assigning an array value to the state in my react project. In order to do this, I have initialized my state as follows: constructor(props) { super(props); this.state = { category: [] } } My objec ...

What makes React Router distinct as a React component?

What is the reasoning behind react-router being a React Component that utilizes React internally? As routing issues were already addressed before the introduction of React Components? In the case where the path property does not align with the URL path, w ...

Determining the ideal scenario for employing server actions versus client components versus server components

I'm currently exploring how to efficiently share data among my components. My focus is on having an auth_token stored in memory that can be accessed throughout the application. Right now, I see two potential approaches: Using a context provider Imple ...

Create a JavaScript array by extracting IDs from an HTML document

Looking to create a function that randomly selects an image defined in HTML code. I've opted to create an array to store all used images and have the function pick from there. Is there a simpler way to define the array or should I skip using it altog ...

`Hovering over a div triggers a continuous animation loop`

I've gone through various questions and solutions related to this issue, but unfortunately, none of them seem to work for me. It's possible that I might be overlooking something or my scenario is slightly unique. The main problem I'm facing ...

What is the best way to attach two separate event listeners to a single button?

I'm attempting to have one button trigger two different functions, but I haven't been successful so far. I tried adding the second event listener as indicated by the // part, but it didn't work. The two functions should be executed sequentia ...

How can I alter the icon's color?

Is it possible for the icon's color to change to red when the condition is greater than 0, and to gray when the condition is equal to zero? <TouchableOpacity onPress={() => { if (Object.values(selectedIt ...

Change the div attribute when clicking on a corresponding link

For the full code, please visit: https://plnkr.co/edit/6TTLVcsXLV7C1qXSMQV0?p=preview Here is an angular ui bootstrap accordion with nested panels: <uib-accordion close-others="oneAtATime"> <div ng-repeat="sub in subdivisions"> < ...

What purpose does the <noscript> tag serve in React?

Recently delving into the world of React, I've been working on a simple application by following this tutorial: https://reactjs.org/tutorial/tutorial.html. I've started modifying the code to suit my own project. While inspecting my HTML, I notic ...

Navigating the route with React Router the correct way

Within my React project, I currently have: A Login component that does not include header and sidebar components. See the login image. A Dashboard component which features a header, footer, and other child components all rendering within it. Check out th ...

the variable exhibits a distinct value within the code

const [arrUserID, setArrUserID] = useState([]) const fetchDataByUserID = async () => { try { const ownerData = await axios({ url: `${baseUrl}/addcryptos/owner/${userid}`, method: 'get' }) ...

Understanding how to override a child function in a parent component using React

Many components are using the PanelHeader component, which includes a refresh icon that triggers the function: this.toggleReload, Instead of just reloading the content, I want to pass a function from the parent component and execute it; (CallMyCustomFunct ...

Using a background image in CSS for horizontal rules can override other styling rules

Encountered an unusual CSS bug: After using background-image to style hr, none of the subsequent rules or selectors are displaying on the page: hr { border: 0; height: 1px; background-image: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0 ...

Storing form data in a file using React

I am trying to create a feature in my react component where instead of submitting a form and sending the data, I want to write this data to a file for later use. Is it achievable using vanilla JS or should I consider using a library? This is how my handl ...

How can we utilize CSS floats to achieve maximum widths?

I currently have 5 divs that I need to structure in a specific way: Each div must have a minimum size of 100px The parent container should display as many divs as possible on the first row, with any remaining divs wrapping to new rows if necessary If the ...

Use jQuery to apply a class to some input elements when certain events like keyup or

If I type something in the input field, it should add a border to the li tag containing the text. The current script works fine, but is there a way to make this jQuery script shorter? Thank you for your help! .add_border{ border: 2px solid #000 !impor ...

Utilize the Math.log() function within an HTML document

I am attempting to incorporate a Math operation in an HTML page, but unfortunately it is not functioning as expected. Here is the code snippet that I have experimented with. Is there any solution to make this code operational? HTML code <div> < ...