Enhancing Material UI Popper with Custom Styling

My Desired Outcome

My Current Situation

I am attempting to use flexbox to achieve a specific layout. However, I am struggling with managing the spacing between two text fields (text and secondaryText). What is the best way to approach this issue?

popper: createStyles({
        root: {
            backgroundColor: white,
            borderRadius: 4,
            boxShadow: "0 2px 12px 0 rgba(0, 0, 0, 0.5)",
            zIndex: 1301,
            maxHeight: 200,
            overflowY: "auto",
            display: "flex",
            flexDirection: "column",
        },
    }),
};

<Popper
       className={toClassName(classes.popper)}
       >             
         {children} // Component AutocompleteSelection
</Popper>

const AutocompleteSelection: FC<AutocompleteSelectionProps> = ({
    text,
    secondaryText,
}): JSX.Element => {
    const classes = useMakeStyles(baseStyles) as Properties;
    return (
        <ListItem styles={listItem}>
            <Typography classes={classes.typography}>
                {text}
                {secondaryText}
            </Typography>
        </ListItem>
    );
};

const baseStyles: Properties = {
    listItem: createStyles({
        root: {
            "&:hover": {
                backgroundColor: greyTwo,
            },
        },
    }),
    typography: createStyles({
        root: {
            fontSize: 14,
            lineHeight: 1,
        },
    }),
};

Answer №1

Hello there! To align secondaryText to the right within a flex display, you can achieve this by using marginLeft: "auto" in the secondaryText class like so:

<Typography class={classes.typography}>
    <Typography class={classes.text}>{"hello"}</Typography>
    <Typography class={classes.secondaryText}>{"there"}</Typography>
</Typography>

And apply the following styles:

const useStyles = makeStyles((theme) => ({
  typography: {
    display: "flex"
  },
  text: {},
  secondaryText: {
    marginLeft: "auto" // secondary text floated to the right
  }
}));

Check out a codesandbox example here.

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

What is the best way to programmatically rotate the background image of a div that employs background-size: cover using Jquery?

I've been attempting to change the background image on a website by rotating through an array of images, but unfortunately, I am encountering difficulties. Despite my efforts, the console doesn't provide any clues as to what might be going wrong. ...

Tips for arranging links in a vertical layout on a navigation bar that is compatible with every device

I'm having trouble aligning the links vertically in the center of the navigation bar, with the logo overlapping the content. Check out the HTML code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

Creating a visually appealing table in HTML or experimenting with a tableless design can greatly enhance your website's layout

Presenting data with headers in HTML has been a challenge for me. Below is the portion of the header I'm having difficulty with. Although I've successfully rotated the text, the issue I'm facing now is text overlap. Here's the code st ...

"Disable the scroll bar for a specific component in Angular while keeping it visible for the

Is there a way to deactivate the overflow: hidden style for just a single component? The style is defined in my style.scss file as shown below: .Visible-scroll{ overflow: auto } ...

Is there an issue with the second bootstrap navbar overlapping a dropdown-menu from the first navbar?

My issue involves two fixed-top navbars, where the dropdown-menu from the first one is being overlapped by the second navbar. I've tried adjusting z-index, positioning, and overflow properties without success. I have also looked at similar questions b ...

Is there a way to make the X-editable datepicker appear next to the date field rather than in the same spot every time?

When utilizing X-editable, I encountered a problem where specifying the datepicker field mode as "popup" results in the popup displaying correctly. However, when dealing with a long table (either vertically or horizontally), the position of the date/dateti ...

How to transform the Material UI functional component Mini variant drawer into a class component in ReactJS

I have been working with the mini variant drawer component from the official material-ui website and I am encountering some issues when trying to convert it into a class component. The errors seem to be related to hooks and are occurring within the node ...

Can Anyone Provide Assistance with CSS for Customizing the Bootstrap 4 Navbar Burger Icon

I am working on implementing a bootstrap 4 navbar into my Angular code base. When the screen size of the browser becomes smaller, I want to hide the navbar and instead display a hamburger icon with a side menu. I have tried a few solutions, but have not b ...

Exploring the use of the map function for iterating in a stepper component of

I've been attempting to integrate Redux Form into my stepper component. However, I'm facing an issue where adding form fields results in them being displayed in all three sections. To address this, I started reviewing the code for the stepper. I ...

Is there a way to prevent the context menu from appearing when tapping on an image on a mobile phone?

When attempting to move an image on the screen with a touch event, a popup appears in Chrome when pressing and holding the image. This popup usually includes options to save the image. Is there a way to disable this popup so I can freely move the image w ...

The type 'EventTarget & HTMLTextAreaElement' does not contain the property 'files'

When trying to call a method in React TypeScript on the onChange Event of a MUI Input field, an error is encountered. The error message received is: Type '(event: { target: { files: any[]; }; }) => void' is not assignable to type 'Chang ...

Element in SwipeableDrawer of Material UI is repositioned on mobile devices while scrolling

Utilizing Material UI's SwipeableDrawer component, I have successfully created a bottom drawer with a fixed action button container. The container is positioned using position: fixed; bottom: 0;. While this setup works effectively on desktop browsers, ...

What is the best way to customize the appearance of an Angular tree component?

I'm attempting to incorporate the style of the ACE Admin theme into the angular-tree-component. Currently, my tree looks like this: https://i.sstatic.net/ktiEf.png However, I desire to apply styles from the Angular tree guide in order to achieve a ...

Difficulty Sorting Dates in Material UI DataGrid

I have a DataGrid in Material UI, and one of my columns displays dates. Following the guidance from the Material UI documentation, I have set the type to "date" in the column array: { field: "submittedAt", headerName: "Submitted", minWidth: 150, flex: 2, t ...

What is the name of the syntax highlighting plugin utilized by the Bulma CSS framework?

Does anyone know the name of the code highlighter plugin that is featured on bulma.io? I have tried looking through all sources and scripts, but I can't seem to find the plugin's name. Attached is a screenshot for reference: https://i.sstatic.n ...

Getting individual user posts sequentially in PHP

As I develop my social networking platform, one challenge I face is how to display user posts individually within a designated div. Similar to Facebook's layout where posts appear one by one and the div expands if the post is lengthy. How can I achiev ...

Using JQuery for sliding left without having to use inline CSS

I am dealing with a situation on my website where I need to hide a sidebar when clicked. $('#sidebar').toggle('slide', 'left', 300) In addition, I have implemented a CSS style to hide the sidebar on mobile devices. #sidebar ...

Triggering the click event on a nested list within Material UI List

In one of my components, I have a Material UI list. Whenever I click an item in this list, it takes me to another listView using the router and onClick method. When I click an item in the first list, "firstList clicked" is printed to the console. However, ...

Navigate through pages using scrollspy without losing your position when returning

Hey all you web geeks out there, I could really use your help solving a little issue. I've been working with Bootstrap to build a website that utilizes scrollspy for navigating different sections of the page using the navbar. The only way I could sto ...