What is the best way to display the complete text or wrap a menu item in an Angular Material menu?

Is it possible to display the full text of a menu item instead of automatically converting it to ellipses or breaking the word? I've tried various CSS methods without success. Any suggestions?

https://i.stack.imgur.com/3l7gE.png

#html code

<mat-menu #reportsMenu="matMenu" class="main-menu reports-mat-menu-panel-customized">
            <ng-container *ngFor="let reportsMenuItem of REPORTS_MENU">
              <button [disabled]="!isAdmin && reportsMenuItem.isOnlyAdminAccess" mat-menu-item *ngIf="reportsMenuItem.submenu; else menuItem" [matMenuTriggerFor]="submenu">
                <span class="material-icons primary-color" style="vertical-align: middle; padding-right: 8px;">
                  {{ reportsMenuItem.icon }}
                </span>
                {{ reportsMenuItem.name }}
              </button>
              <ng-template #menuItem>
                <button mat-menu-item (click)="goToSubReports(reportsMenuItem.value)">
                  <span class="material-icons primary-color" style="vertical-align: middle; padding-right: 8px;">
                    {{ reportsMenuItem.icon }}
                  </span>
                  {{ reportsMenuItem.name }}
                </button>
              </ng-template>

              <mat-menu #submenu="matMenu">
                <ng-container *ngFor="let submenuItem of reportsMenuItem.submenu">
                  <button [disabled]="!isAdmin && submenuItem.isOnlyAdminAccess" mat-menu-item *ngIf="!submenuItem.submenu?.length" (click)="goToSubReports(submenuItem.value !== undefined ? submenuItem.value : null)">
                    {{ submenuItem.name }}
                  </button>

                  <ng-container *ngIf="shouldShowSubmenu(submenuItem) && submenuItem.submenu?.length > 0">
                    <button mat-menu-item [matMenuTriggerFor]="submenusub">
                      {{submenuItem.name}}
                    </button>
                  </ng-container>
                </ng-container>>

              </mat-menu>

              <mat-menu #submenusub="matMenu">
                <button [disabled]="!isAdmin && submenuItemSub.isOnlyAdminAccess" mat-menu-item *ngFor="let submenuItemSub of getSubMenu(reportsMenuItem.submenu, 'Available Properties')" (click)="goToSubReports(submenuItemSub.value !== undefined ? submenuItemSub.value : null)">
                  {{ submenuItemSub.name }}
                </button>
              </mat-menu>
            </ng-container>
          </mat-menu>

Answer №1

To ensure that the span does not extend beyond its parent element, apply the CSS property word-break: break-all;. Check out the example below for a better understanding!

.mat-mdc-menu-item .mat-mdc-menu-item-text {
  width: 100% !important;
  overflow-wrap: break-word !important;
}

Visit stackblitz for demonstration


For more information, refer to:

The original solution on Stack Overflow

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

I'm getting an error about uncaught products in a collection - can you help me understand what this means and how to

My next.js website, which fetches products from Shopify, was working flawlessly until a few months ago when it suddenly stopped building on the development server. Now, whenever I try to run the website locally, I am encountering a "Cannot read properties ...

Why is MutationRecord[] organized as an array in MutationObserver?

I've been diving into the world of MutationObserve, and I've grasped most of it. However, one thing that's puzzling me is why the parameter requires an array. According to the documentation: An array of MutationRecord objects, detailing e ...

The image appears uniquely sized and positioned on every screen it is viewed on

After reviewing the previously answered topics on the site, I couldn't seem to make the necessary adjustments. Despite setting the size and location in the css file, the large image remains centered and fitting for the screen. The "imaged1" class seem ...

Versioning resources in Spring MVC with Thymeleaf

https://i.sstatic.net/ArllV.png Struggling with resource versioning in Spring Mvc 4 while using thymeleaf template engine. Despite the code provided, I am unable to see the new version URL when viewing the page source. What could be causing this issue? Wh ...

Divide the parsed rss findings into separate parts

I am in the process of developing a project that involves aggregating job listings from various websites by parsing their RSS feeds. I am utilizing rss-parser for this purpose. Each feed has its own format for the title field, resulting in varying structu ...

What is the purpose of using the "::before" CSS modifier to display the fontawesome chevron in the specified Bootstrap accordion code?

I stumbled upon a great example of adding arrows to the Bootstrap accordion on CodePen. Check it out: https://codepen.io/tmg/pen/PQVBGB HTML: <div class="container"> <div id="accordion"> <div class="card"& ...

Creating a dynamic navigation bar that adjusts to changing content requires careful planning and implementation

Struggling with achieving my visual mockup while designing a webpage: Check out my web design mockup Currently focusing on section 2 of the page. Using Angular 5, Bootstrap 3, and ngx-bootstrap library to integrate Bootstrap components into Angular. Here ...

Encountering an Error in Angular Material 8 due to the Import of the Unforeseen Directive 'MatCard'

I keep encountering the error message displayed above in the console. I am currently working with Angular Material version 8.2.3. In my app.module.ts file, I have the following import statements related to Angular Material: import { MatInputModule, MatBu ...

What could be the reason behind my image displaying correctly in the majority of browsers, yet not in Internet Explorer

The HAML code below is what I have: %header .grid %a{:name => "top"} .logo %a{:href => root_path} =image_tag("logo3.png") .tagline .clearfloat %p Fast Facts About Your Website, Your Competitors And Best ...

Switch from Gulp-TSLint to Gulp-ESLint for enhanced code analysis!

I am currently in the process of updating a Gulp task that uses gulp-tslint to now use gulp-eslint. The code snippet below outlines the changes I need to make: const { src } = require('gulp'); const config = require('./config'); const ...

Oops! Looks like there was an issue with defining Angular in AngularJS

I am encountering issues while attempting to launch my Angular application. When using npm install, I encountered the following error: ReferenceError: angular is not defined at Object.<anonymous> (C:\Users\GrupoBECM18\Documents&bs ...

Integrate geographic data in GeoJSON format into a Leaflet map by using the Django template

In my Django view, I am fetching results of an SQL query and rendering it on the index.html page of my web map. The POST request successfully returns the acreage calculated from the SQL query to the page. I am also attempting to display the geojson data fr ...

Is there a way to partially conceal the H2 text using CSS?

Is there a way to partially hide H2 text using CSS? I have the following code: HTML: <div class="twocol-box1 superflex-content-6-12"> <h2 data-content="My - Text&amp;nbsp;<span style=&quot;float:right;&quot;>M ...

Show the Canvas element at the back of the DIV

This particular question requires a clear explanation. My goal is to have the canvas act as a background element on the page, while the main content of the page starts in its usual position. I attempted using separate DIVs with their own Z-index values, bu ...

How can I edit this code in JSPDF to print two pages instead of just one?

Currently, I have a script that can generate a PDF from one DIV, but now I need to create a two-page PDF from two separate DIVs. How can I modify the existing code to achieve this? The first DIV is identified as #pdf-one and the second DIV is #pdf-two. p ...

As I attempt to log in, the GitHub API is sending back a message stating that authentication

const fetchUser = async () =>{ let usernameValue : any = (document.getElementById('username') as HTMLInputElement).value; let passwordValue : any = (document.getElementById('password') as HTMLInputElement).value; const ...

What is the best way to modify directives in response to updates in services?

In my directive (parent-directive), I have a slider called mySlider. When the slider is stopped, it triggers an event that calls an Angular $resource service with two parameters. The service then returns an object. The structure of the directives is as fo ...

"Why does the useEffect in Next.js fire each time I navigate to a new route

Currently, I have implemented a useEffect function within the Layout component. This function is responsible for fetching my userData and storing it in the redux-store. However, I have noticed that this function gets triggered every time there is a route c ...

What is the way to retrieve an array property in a typescript interface?

Imagine a scenario with three interfaces structured as follows: registration-pivot.ts export interface RegistrationPivot { THead: RegistrationPivotRow; TBody: RegistrationPivotRow[]; } registration-pivot-row.ts export interface RegistrationPivotR ...

Customize the text for the material icon

Can I customize an icon by using the following code: import FiberNewIcon from "@mui/icons-material/FiberNew"; Is there a way to add custom text to the icon? ...