Material UI List and ListItemText: The ultimate test of readability without wrapping

Can I stop text from wrapping in ListItemText?

https://i.sstatic.net/08eB1.png

I want ListItemText to truncate words without expanding or scrolling.

Thank you

Answer №1

With the release of Material UI version 5.0.6, it is now possible to customize the ListItemText component using the primaryTypography prop.

For more detailed information, refer to the ListItemText Api Documentation

primaryTypographyProps: These properties will be passed down to the primary typography component (unless disableTypography is set to true).

This implies that the specified props will be transferred to a Typography Component

To control the visibility or wrapping of text, you can limit the width of the ListItem (if necessary based on its parent) by setting the maxWidth to 300px. Then utilize the primaryTypographyProps and provide a style object with settings for hiding the text such as whiteSpace, overflow, and textOverflow.

import { ListItem, ListItemText } from '@mui/material';

<ListItem
    sx={{
        maxWidth: 300
    }}
>
    <ListItemText
        primary={"Super long string that needs to be wrapped"}
        secondary={"other text not important"}
        primaryTypographyProps={{ 
            variant: 'subtitle2', 
            style: {
                whiteSpace: 'nowrap',
                overflow: 'hidden',
                textOverflow: 'ellipsis'
            }
        }
        secondaryTypographyProps={{ variant: 'caption' }}
    />
</ListItem>

If you require more customization, you have the option to disable Typography and provide your own component with unique styling preferences.

disableTypography: When set to true, the children will not be enclosed within a Typography component. This feature can be beneficial for implementing an alternative Typography design by enclosing the children (or primary) text along with optional secondary text within the Typography component.

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

Obtain the URL link from Unsplash where the picture is sourced

As I work on a website, I incorporate a link () to display a random photo. However, the photo refreshes periodically and upon loading the site, all that is visible is this default link: . Is there a method to extract the actual source like so: "". Althou ...

Building user interfaces using React with Material Design components

Can Material UI be utilized with stateless components, or is having state a necessity? I was looking to incorporate Popovers, and based on the provided code example, it seems like state is essential for this feature. ...

Ensuring that all Tab-Elements have an equal width based on the length of the longest text within them

Is it possible in the MUI-JS framework to automatically adjust the width of all Tab elements so that they are equal, based on the length of text within the longest Tab? This means that a Tab with only two characters would have the same width as one with 3 ...

What is the method to conceal an element after detecting and locating a specific class using jQuery?

Can someone please assist me today with the following task: Step 1: <div id="htmlData"> <div class="col-md-12"> <div class="pull-left"> <h3>Report: <strong>Travel </strong></h3> ...

Assess the scss styles specific to components following the global min.css in a React application

ISSUE Imagine we have a min.css file that needs to be imported globally: index.js import ReactDOM from "react-dom"; import App from "src/App"; import "library/library.min.css"; ReactDOM.render(<App />, document.getE ...

What causes the text-align property to function in varying ways across different tags?

Can you explain why the text-align property behaves differently on different tags? In two cases, I am trying to center my text. In the first case, I use a parent div tag with an anchor tag inside. When I need to center align, I apply the property to the p ...

Issue: MUI Alert - For the data grid to function properly, each row must be assigned a unique `id` property

Trying to populate a Datagrid by fetching data from an API: const [invoiceList, setInvoiceList] = useState({id: 0}) useEffect(()=>{ axios.get("http://localhost:3001/invoices").then((response)=>{ setInvoiceList(response.data) ...

Modify the layout of the date selector to display weekdays instead - material ui

How can I change the datepicker format to display weekdays (Monday, Tuesday,..) instead of MM/dd/yyyy? Currently, the datepicker is set up with the format format="MM/dd/yyyy". Would it be possible to modify this? Here is the source code: <MuiPickers ...

Is there a way to encase numerous <tbody> elements together?

My table design has specific css requirements where I am using multiple <tbody> tags. It looks like this: Example with multiple tbody tags However, I also need a wrapper for the multiple tbody tags (similar to a common tbody parent) that can be scr ...

The CSS-styled button I created is designed to display a list and has the functionality of submitting

Whenever I click on a button, it's supposed to show a list of choices. But instead, it tries to submit the values in the text input field. Css .dropbtn { background-color: #3498DB; color: white; padding: 16px; font-size: 16px; border: none; cursor ...

Is it possible to apply Border Radius exclusively to round the top of a div?

When applying the border-radius property on a div element with borders, it only affects the top corners. But why is that? For example, you can check out this demo: https://jsfiddle.net/07tqbo56/1/ .asd { margin-top: 35px; ...

Ensure that the container div is filled by the image if the image exceeds the dimensions of

I have a footer menu with a background image that is larger than the div itself (2000x168). Even though I have set the width to 100%, it seems like the whole image isn't displaying. Instead, only a portion of it is visible, matching the size of my sc ...

Steps to ensure text is consistently positioned at the bottom of the page using CSS

I have a simple form created using only HTML and CSS, and my goal is to position the "version text" at the bottom of the page. Please refer to the image below for the desired outcome. Here is the code I am currently using: <!DOCTYPE html> <htm ...

How can z-index and relative positioning be used to center a button with jQuery and CSS?

One issue I am facing is with a button that is located in the center of another div (container). When the button is clicked, some hidden divs appear within this container. Although they are present but initially set to display: none using CSS, and then sho ...

All images must be arranged to fit seamlessly side by side regardless of the screen size

I'm currently experimenting with creating a website dedicated to my favorite TV shows. Upon entering the site, you are greeted with the main page that includes 7 images. Each image is linked to a specific webpage providing information about the corre ...

Issues arise when implementing a sticky position using CSS with incomplete functionality

I want to create a website with a menu bar that stays at the top even on long pages. However, when I use position: sticky in CSS, the menu disappears after scrolling a certain distance. Does anyone know how to fix this issue? HTML: <nav> <ul cla ...

New design for Bootstrap navigation bar logo

I'm having trouble trying to display different logos for mobile devices and desktop/tablets. I attempted to use the code provided on this thread about displaying a different logo on mobile and desktop, but it doesn't seem to be working for me. Th ...

Tips for adjusting the size of your Navigation bar

I've noticed that most of the questions I've come across are related to WordPress or Bootstrap nav bars, which I'm not familiar with. I've created mine using CSS. I want to enhance my navigation bar for mobile users by making the butto ...

Tips for aligning a div (or any other content) in the center of a

I recently added a small div to my webpage to display 3 options in a stylish way, but I'm encountering an issue - the box is appearing on the left side instead of the center. I have tried using various CSS properties like align-items, align-content, a ...

Out of nowhere, Div became completely unresponsive

As part of my lesson plan on jQuery, I wanted to demonstrate a sliding effect using a div element. Initially, the sliding worked fine when clicked, but then I tried adding code for hiding another element and encountered issues. Even after removing the new ...