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

What is the best way for a parent process to interrupt a child_process using a command?

I'm currently in the process of working on a project that involves having the user click on an 'execute' button to trigger a child_process running in the backend to handle a time-consuming task. The code snippet for this operation is shown b ...

How can I update the background color of the specified element when the text changes without triggering a postback?

Seeking guidance on JavaScript as I am not very adept in it. We have a webpage where users upload .XLS/.CSV files and review the data before submitting it to our database. Users can edit cells in the uploaded document on our "review" screen before final su ...

Splitting the div into two columns

I've encountered various solutions to this issue, but when I integrate an Angular2 component inside the divs, it fails to function properly. Here is my progress so far: https://i.stack.imgur.com/qJ8a9.jpg Code: <div id="container"> <div ...

Can a static text be displayed randomly using Javascript?

What I'm searching for is a unique text display feature that's different from scrolling. I envision a subtle fade in/out effect, but it's not necessary. The main goal is to fit within a small area on a website with limited vertical space - ...

A standard procedure for evaluating an application using JavaScript on the client side

I am looking to streamline E2E testing for a web application. The frontend of the app is built on a JavaScript framework, while the backend uses Java technology. While I am aware of the tools and frameworks available for JavaScript testing, I am curious ...

Effortless bug tracking in Chrome developer tools

When I'm debugging, I want the code to be displayed in Chrome browser (or another browser like Edge) exactly as it was written. Even when using pretty print, the code still appears unreadable. For example, a block of code written in my IDE: {provideD ...

macangular 2 template for developing with servicestack

Is there a method to create a project on a Mac using Rider or VS Code without the need for Visual Studio? I prefer not to install Windows just to create an empty project to test out a potentially useful template. ...

Tips on how to customize an HTML form submission appearance

Take a look at my file upload form below: <form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="filetoupload" id="filetoupload" onchange="this.form.submit();"> </form> I am trying to figure out ...

executing jQuery toggle on freshly generated content

I have a webpage that I designed using jQuery. Within this page, there is a table with rows assigned specific color classnames (e.g., tr class="yellowclass"). Users can filter the rows by clicking checkboxes to show/hide tables of different colors. The i ...

Utilizing $asyncValidators in angularjs to implement error messages in the HTML: A guide

This is my first major form with validations and more. I've set up a Registration form and I'm utilizing ng-messages for validation. The issue arises when I have to check the username, whether it already exists in the JSON server we are using or ...

Encountering a tuple type TypeScript error with a spread argument is far too frequent an occurrence

Encountering this error is becoming a frequent occurrence for me, and I am currently unable to resolve it. src/graphics.ts:105:55 - error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter. 105 _queue.forEach((_ ...

Oops! Looks like an issue has popped up: using require() of an ES module is not supported when using recharts in combination with next.js

I've noticed some similar questions, but none of them seem to address my particular issue. I'm currently working on a webapp using next.js (with typescript). Within the app, I am utilizing recharts, however, I am encountering a compilation error: ...

Combining and organizing Javascript files for efficient loading and reusable code functionality

I've been tasked with cleaning up a project that contains around 45-50 separate .js javascript files. I'm trying to figure out the most effective way to reduce their loading size. Should I combine all the files into one using npm or gulp? Or shou ...

Tips for setting the style of child components in a ReactJS project with CSS modules, classNames, and JSX syntax

Currently in the process of setting up a project using React JS and I am interested in incorporating auth0 for authentication purposes, along with potentially integrating some serverless functions. auth0 conveniently offers a pre-made "seed" project at ht ...

Create a Typescript index signature that incorporates individual generic types for each field

Many times, the keys of a record determine its value. For instance: const record = { [2]: 5, ["string"]: "otherString", ["there is"]: "a pattern" } In these instances, each key of type K corresponds to the ...

Is there a way to programmatically simulate clicking on the "Cancel search" button?

I have a text input field with type "search". In order to perform UI testing, I need to simulate clicking on the "cancel search" button: The code for this specific input field is as follows: <input type="search" value="user"> Although the cancel b ...

Finding the text within a textarea using jQuery

My journey with jQuery has just begun, and following a few tutorials has made me feel somewhat proficient in using it. I had this cool idea to create a 'console' on my webpage where users can press the ` key (similar to FPS games) to send Ajax re ...

Tips on employing the sendkeys function in selenium webdriverjs through promise chaining

Here is the coding snippet: driver.get(url).then(function(){ txtFnn = driver.findElement(webdriver.By.xpath(xpath)); return txtFnn; }).then(function(){ txtFnn.sendkeys("12345678"); }) Issue: An error occurred: Typ ...

Positioning elements at the bottom of the container

There is a dilemma that only those in the world of web development will understand. Beware! I have envisioned a layout for a website I am constructing. The concept involves tilted <hr/> elements on the page, with text wrapping around them (refer to ...

Exploring the concepts of express post and delete responses that are unclear

It appears that I am facing an issue where trying to access an attribute of an element from a JSON file returns null. Additionally, I am still encountering npm audit problems. What are your thoughts on this situation? Below is the code snippet that has be ...