Skip to content

Commit

Permalink
fix: div handle not working for svg element (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
airchen233 authored May 20, 2023
1 parent 294c2a0 commit 1c27ca1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ export class AngularResizableDirective implements OnInit, OnChanges, OnDestroy,
* */
@Input() rzHandles: ResizeHandleType = 'e,s,se';

/**
* Using exist handles for resizing instead of generate them.
* @example
* [rzHandleDoms] = {
* e: handelE,
* s: handelS,
* se: handelSE
* };
* */
@Input() rzHandleDoms: {
se?: ElementRef;
sw?: ElementRef;
ne?: ElementRef;
nw?: ElementRef;
n?: ElementRef;
e?: ElementRef;
s?: ElementRef;
w?: ElementRef;
} = {};

/**
* Whether the element should be constrained to a specific aspect ratio.
* Multiple types supported:
Expand Down Expand Up @@ -274,13 +294,14 @@ export class AngularResizableDirective implements OnInit, OnChanges, OnDestroy,
/** Use it to create a handle */
private createHandleByType(type: string, css: string): ResizeHandle {
const _el = this.el.nativeElement;
const _h = this.rzHandleDoms[type] ? this.rzHandleDoms[type].nativeElement : null;

if (!type.match(/^(se|sw|ne|nw|n|e|s|w)$/)) {
console.error('Invalid handle type:', type);
return null;
}

return new ResizeHandle(_el, this.renderer, type, css, this.onMouseDown.bind(this));
return new ResizeHandle(_el, this.renderer, type, css, this.onMouseDown.bind(this), _h);
}

private removeHandles() {
Expand Down
11 changes: 6 additions & 5 deletions projects/angular2-draggable/src/lib/widgets/resize-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export class ResizeHandle {
protected renderer: Renderer2,
public type: string,
public css: string,
private onMouseDown: any
private onMouseDown: any,
private existHandle?: Element
) {
// generate handle div
let handle = renderer.createElement('div');
// generate handle div or using exist handle
let handle = this.existHandle || renderer.createElement('div');
renderer.addClass(handle, 'ng-resizable-handle');
renderer.addClass(handle, css);

Expand All @@ -22,7 +23,7 @@ export class ResizeHandle {
}

// append div to parent
if (this.parent) {
if (this.parent && !this.existHandle) {
parent.appendChild(handle);
}

Expand All @@ -41,7 +42,7 @@ export class ResizeHandle {
this._handle.removeEventListener('mousedown', this._onResize);
this._handle.removeEventListener('touchstart', this._onResize);

if (this.parent) {
if (this.parent && !this.existHandle) {
this.parent.removeChild(this._handle);
}
this._handle = null;
Expand Down

0 comments on commit 1c27ca1

Please sign in to comment.