Angular 8 offers the functionality of a mat-dialog that is both draggable and resizable, providing

In search of a solution to enable both dragging and resizing for a mat-dialog. I have successfully implemented the dragging functionality using cdkDrag (DragDropModule). However, when trying to use resize: booth; in CSS, it seems to conflict with the draggable feature. Removing cdk allows resizing to work, but then dragging is disabled, and vice versa.

To view the code, click here: https://stackblitz.com/edit/angular-vp8xt7

Answer №1

When working with your StackBlitz, you may notice a resize handle appearing at the bottom right of the dialog window, indicating that you are on the right track. However, there seems to be an issue where the mouse events are being consumed by the dragging functionality instead of being passed to the resizing functionality.

To resolve this issue, try adding a cdkDragHandle to the h1 element in your code:

<h1 mat-dialog-title cdkDrag cdkDragRootElement=".cdk-overlay-pane" cdkDragHandle>

You can see how this solution works in action by checking out your modified version in the forked StackBlitz.

Answer №2

To make the mat dialog component resizable:

You can apply the following CSS to the panel class:

.custom-mat-dialog-panel .mat-dialog-container { 
  resize: both;
}

In your TypeScript file:

openDialog() {
    this.dialog.open(HelloComponent,{height:'100px',width:'100px', panelClass: 'custom-mat-dialog-panel'});
}

To make the mat dialog component draggable:

<div mat-dialog-title cdkDrag cdkDragRootElement=".cdk-overlay-pane" cdkDragHandle>
 Draggable Title
</div>

Answer №3

I encountered similar requirements and challenges.

Here's the solution that worked for me in Angular 13:

Global CSS-File:

.resizable-mat-dialog-panel {
  resize: both;
  overflow: auto;
  max-width: unset !important;
  max-height: unset !important;
  position: absolute !important;
}

TS File with openDialog:

openDialog() {
    this.dialog.open(TestComponent,{height:'100px',width:'100px', panelClass: 'resizable-mat-dialog-panel'});
}

Dialog HTML:

<h1 cdkDrag
    cdkDragRootElement=".cdk-overlay-pane" 
    cdkDragHandle>
    Test header
</h1>
...

If position: absolute is not used, full resizing functionality may be restricted. This can lead to issues where resizing a dialog from left to right after moving it from the center becomes problematic. Applying position: absolute resolves this limitation.

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

Want to learn how to display a description below a photo when you hover over it in a photo gallery?

I am currently creating a basic photo gallery where hovering over a thumbnail displays an enlarged photo below it. My goal is to also have text displayed inside a white text box when hovering over each thumbnail, with unique descriptions for each. I need ...

Concealing forms within an Angular 5 application

I'm currently working on displaying the terms of use on the initial screen along with two buttons. If the user clicks the accept button, they will be directed to the authentication form. However, if they click refuse, the "Refused Terms" screen will a ...

Combining two RxJs observables to create selectable options for a material drop-down menu

I'm encountering issues while attempting to combine two different observables and display the results in a Material Select component. This example (created using the Material docs tool) demonstrates what I'm trying to achieve. However, the optio ...

Synchronizing Headers in the Angular PDF Viewer Control by Syncfusion

We implement token-authentication on our endpoints and I am interested in using the standard approach provided by Syncfusion for viewing a PDF. My main concern is whether it's feasible to include headers with the request. Although I have posted this q ...

Shifting Angular Component Declarations to a New Location

Here's a question that might sound silly: In my Angular project, I am looking to reorganize my component declarations by moving them from angular.module.ts to modules/modules.modules.ts. The goal is to structure my src/app directory as follows: src ...

Angular 9 TestBed RouterTestingModule: Exploring the router.url Readonly Property

While transitioning from Angular 8 to Angular 10 in stages, I encountered an issue when upgrading to version 9. All of my TestBed.get(Router).url calls started throwing errors because the property had become read-only. For instance, the code TestBed.get(R ...

Ensure that the flex item spans the entire width of the page

I'm struggling to make my audio-player resize properly to fit the full width of my page. I can't seem to figure out what I'm missing or doing wrong... (Current Look) https://i.sstatic.net/tEtqA.png I'm attempting to utilize HTML cust ...

There is a button on my website that uses a small piece of Javascript to post a tweet, but unfortunately, it is not functional on mobile devices

Check out this link to view the demonstration - http://codepen.io/illpill/pen/VbeVEq function sendTweet(message, author) { window.open('https://twitter.com/intent/tweet?hashtags=thequotemachine&text=' + encodeURIComponent('"' + m ...

Webkit feature: Rounded border image overlay

One issue arises when applying a rounded border to an image in webkit browsers as the border ends up hidden behind the image. CSS img { border: 10px solid #000; border-radius: 100%; } HTML <img src="http://25.media.tumblr.com/tumblr_mbje ...

Confirming that the NGRX Dictionary value is set

After upgrading from Angular 7.1.4 to 8.2.0 and Typescript from 3.1.6 to 3.5.3, I encountered an issue with identification of array items. Prior to the upgrade, TypeScript correctly recognized that the array item was not undefined. However, post-upgrade, ...

Angular: Issue with setting a new value in child component on the second attempt via @Input directive

Implementing a child component to manage a dropdown feature. The parent component includes a reset button to revert the user's selection in the dropdown (child component) back to 'None'. Check out the code link here. app.component.html: ...

What can I do to ensure my text appears closer to the top of the page?

To achieve the desired outcome of displaying "(även uppfinnare)" at the top row, you can use the following HTML: <div class="data-box"> <div class="personName"><strong> 3. Kee Marcello&nbsp; </strong>< ...

What steps should I follow to make a sticker adhere to a div?

I'm currently in the process of designing a sticker that attaches to the top of a div, much like this: https://i.sstatic.net/aG329.png <div className="upgrade-premium"> <div className="upgrade-team"> <h1>Prem ...

What is the best way to compare two TypeScript object arrays for equality, especially when some objects may have multiple ways to be considered equivalent

Currently, I am in the process of developing a cost function for a game where players are given a set of resources in their hand. The resources can be categorized into different types such as Fire, Air, Water, Earth, Good, Evil, Law, Chaos, and Void. Thes ...

The error code TS2322 indicates that the type 'object' cannot be assigned to type 'NgIterable<any>'. Furthermore, the type 'object' is not compatible with type 'Iterable<any>'

I'm attempting to utilize the HTTP library within Angular to retrieve information from a link containing a JSON file, but unfortunately, I am encountering some issues with it. api.server.ts: import { Injectable } from '@angular/core'; impor ...

Checkbox in Bootstrap should be displayed before the submit button on smaller screens

I've been searching for a solution to this issue without any luck. In my setup, there are three input fields and a submit button displayed side by side on large screens, enclosed in <div class="col-sm"> to stack vertically on mobile devices. Ho ...

An individual in a chat App's UserList experiencing issues with incorrect CSS values. Utilizing Jquery and socketio to troubleshoot the problem

Currently, I am testing a new feature in a chat application that includes displaying a user list for those who have joined the chat. The challenge is to change the color of a specific user's name on the list when they get disconnected or leave the cha ...

Customizing the tab content background color in MaterializeCSS

I've been struggling to customize the background color of my MaterializeCSS tabs content by referring to their official documentation: If you visit the website, you'll notice that the default tabs have a white background, while the 'Test 1& ...

Evaluating string combinations in JavaScript using valid comparisons

After choosing values on the screen, two variables store their value. var uval = '100'; var eval = '5'; There are 2 combinations with values: let combination1= 'u:100;e:1,4,5,10' let combination2 = 'u:1000;e:120,400,500, ...

What is the process for integrating unit tests from external sources into an Angular project following an upgrade to version 15

As of Angular v15, the require.context function has been removed from the test.ts configuration file. I used to rely on require.context to expose tests outside of the Angular project to Karma. Now that it's no longer available: const contextGlobal = ...