How to place an icon on the upper right corner of a mat-menu in Angular 6

https://i.sstatic.net/LHfOm.pngI am currently utilizing mat-menu component.

<mat-menu #appMenu="matMenu" yPosition="above">
  <button mat-menu-item>Settings</button>
  <button mat-menu-item>Help</button>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu">
  <mat-icon>more_vert</mat-icon>
</button>

My objective is to have the mat-menu pop up above the more_vert icon when clicked, with an additional icon in the top-right corner of the mat-menuhttps://i.sstatic.net/RqKiU.png In the provided image, the new icon should be located at the top-right corner and overlay the more_vert icon.

I would greatly appreciate any assistance on how to achieve this.

Included below is the code for a table where the mat-menu is embedded within table data.

 <table class="table">
          <thead>
            <tr>
              <th>Data 1
              </th>
              <th>Data 2
              </th>
              <th>Data 3
              </th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of Data</td>

              <td>
              {{data.val1}}
              </td>
              <td>
               {{data.val2}}
              </td>
              <td>
                      <mat-menu #appMenu="matMenu">
                          <mat-icon>close</mat-icon>
                          <button mat-menu-item>Settings</button>
                          <button mat-menu-item>Help</button>
                        </mat-menu>

                        <button mat-icon-button [matMenuTriggerFor]="appMenu">
                          <mat-icon>more_vert</mat-icon>
                        </button>
              </td>
            </tr>
          </tbody>
        </table>

Answer №1

To get the desired outcome, follow the instructions below:

component.ts

<mat-menu #appMenu="matMenu" yPosition="above">
  <mat-icon class="icon">close</mat-icon>
  <button mat-menu-item>Settings</button>
  <button mat-menu-item>Help</button>
</mat-menu>

<button mat-icon-button [matMenuTriggerFor]="appMenu">
  <mat-icon>more_vert</mat-icon>
</button>

component.css:

mat-icon {
  float: right;
  margin-right: 10px;
}

.icon {
  position: relative;
  top: 14px;
  right: -10px;
  z-index: 9999;
}

style.css:

.cdk-overlay-container {
  position: relative;
  top: -70px;
}

Here is a link to the code sample for reference - https://codesandbox.io/s/k98pz5l98r

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

Tips on navigating the scroller vertically as the user interacts with a selected div by scrolling up and down

On my webpage, I have various div elements displayed. Each div has the options to move it up or down using the buttons labeled "UP" and "Down". When a user selects a div, they can then use these buttons to adjust its position. I am looking for a way to au ...

What are the best ways to optimize and capitalize on functionality in Electron.js?

After creating three custom buttons for the close, maximize, and minimize functions in Electron.js, I encountered an issue. While the close button is functioning properly, I am struggling with implementing the maximize and minimize buttons. In fact, I have ...

Challenge with VueJS structure

I've been working on making nestable DOM elements draggable with VueJS and I've made some progress. However, after dragging and dropping, it seems like some elements are disappearing. Could someone please review my code and point out what might ...

Exploring the ckeditor5-typing plugin within CKEditor

Currently, I am in the process of developing a soft keyboard using CKEditor. One part of this involves transforming text upon input (which I have completed) and occasionally needing to delete a key (where I am currently facing challenges). Below is the sni ...

Using RxJS to send a single API request from a function that could potentially be invoked multiple times

snippet controller: private updateSplitScreenService = () => { this.splitScreenService.emitNewState(this.products); this.splitScreenService.emitNewState(this.stores); }; splitScreenService: // In the code snippet above, a custom debounce fun ...

Display movie details in a responsive column layout that condenses into a single column

I'm having trouble displaying movie information on a website due to CSS and HTML issues. My goal is to align the title (Director:, Cast:, etc) with the first item in the list, and have all subsequent items follow below. I initially tried using a defin ...

Angular Recurring Request

Currently, I am using Angular5 and making requests every 5 seconds to check the status of a task. However, I would like to implement a more flexible condition where if the request receives a status code of 202, continue sending requests, but if it receives ...

Display elements conditionally based on the result of an asynchronous operation within an ng

Using Angular version 11.0.2 I am encountering issues with the async pipe inside an ngIf template, where my data is not being properly refreshed. To illustrate this problem, I have created a simplified example. View code on Plunker To reproduce the issu ...

Stylish CSS selector

Is there a way to target CSS path based on the style of an element? For instance, if I have two ul elements on a page - one with a style of list-style-type: lower-alpha;: <ul start="1" style="list-style-type: lower-alpha;"> and the other ul without ...

Can nswag (TypeScript) be utilized to automatically generate personalized HTTP Headers?

I utilize the nswag npm package to generate HTTP services, interfaces, and more. A sample TypeScript code for a typical service proxy is shown below: @Injectable() export class TenantsServiceProxy { ... constructor(@Inject(HttpClient) http: HttpClien ...

In ReactJS with Bootswatch, the font styles are not applied

I have experimented with various methods to apply this font, but it is still not functioning correctly. @font-face { font-family: 'Samim'; src: local('Samim'), url(./resources/fonts/Samim.ttf) format('truetype'); fon ...

How can I personalize the preview feature in a Bootstrap rich text editor?

Currently, I am utilizing Bootstrap's rich text editor by this method $('#editor').wysiwyg();. Utilizing AJAX, I am passing the HTML content created by .wysiwyg to save it in the database. Later on, I plan to retrieve the saved HTML data to ...

Locating a File in the Bootstrap 4 File Explorer

Bootstrap 4's file browser lacks the file name display, showing only "Choose file...". To address this issue, I created a JavaScript solution. Are there any alternative methods to solve this problem? HTML <label class="file"> <input typ ...

In what way is the background-color of WindowInfoBackground utilized?

I attempted to implement background-color : WindowInfoBackground;. The property background-color : WindowInfoBackground; allows for the assignment of the system color to the background-color attribute. Despite using this particular value, the backgroun ...

What is the best way to alter the background of a div when hovering over a button in a separate div?

Looking to change the background of one div when hovering over a button in another div? Hello, I have a task where I need to modify the background color of a specific div when a button below it is hovered over. The setup involves having an image (a tshir ...

Display only the div on an iPad screen

Is there a way to show this DIV only on an iPad screen? I've looked around on Google for solutions, but none of them seem to work. It always ends up displaying on my computer as well. Is it possible to make it show only on an iPad screen? @media only ...

The content of the DIV element is not displaying properly when trying to list items

I have a div that is styled with the following CSS properties : HTML <div class="messageContainer"></div> CSS .messageContainer { margin-left: 2px; background-color: #F7F5F2; width: 100%; min-height: 50px; border: solid 1px silver ...

css Sibling elements restricted within parent container

Encountering an issue with a star rating css example when more than one fieldset is added. The current CSS code seems to be working fine, but it fails when multiple instances of the same elements [fieldset] are present. I've been struggling to find a ...

What is the best way to transform a Storybook typescript meta declaration into MDX format?

My typescript story file is working fine for a component, but new business requirements call for additional README style documentation. To meet this need, I am trying to convert the .ts story into an .mdx story. However, I am facing challenges in adding de ...

Sometimes the PDF does not display even though the iframe src attribute is updating in Angular 6

I have encountered an issue with displaying a PDF file in my code. Sometimes the PDF shows up correctly, but other times it fails to load. I even tried using an iFrame instead of embed but faced the same scenario. Can anyone provide assistance? Here is my ...