Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing the drag handler #69

Open
Langstra opened this issue Jul 25, 2022 · 8 comments
Open

Customizing the drag handler #69

Langstra opened this issue Jul 25, 2022 · 8 comments
Labels
enhancement New feature or request

Comments

@Langstra
Copy link
Contributor

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:

Current behavior

When making a dialog draggable it receives a default drag handler.

Expected behavior

Even though we can style it using css, it would be useful in certain situations (and semantically more correct) to have a custom drag handler specified in the Component or template itself.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

Wanting the drag handler in a different place.

Having an overflowing/scrolling modal where the drag handler needs to be something fixed in the header of the dialog.

Solution direction

There is a dialogDragHandle on the DialogDraggableDirective, but I do not know how we could use that one. Since it is not accessible from the component or through the ref.

@NetanelBasal
Copy link
Member

What about passing a selector or element when opening a dialog?

@Langstra
Copy link
Contributor Author

That sounds alright to me, however then when opening a dialog there is a separation of concern. The component you pass as the first parameter needs to have the selector or element and you need to specify that element/selector in the component.
Is it possible to add a template reference in the component and define a viewchild or something on it?

@Component({
  selector: 'app-custom-drag-handler-dialog',
  template: `
    <div class="header" #dragHandler>
      <h2>Drag me using the header</h2>
    </div>

    <div class="content">
      <p>Some nice content over here</p>
    </div>
  `,
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class CustomDragHandlerDialogComponent implements OnInit {
  @ViewChild('dragHandler', { static: true }) handle: ElementRef;

  constructor(public ref: DialogRef<DialogData>) {}

  ngOnInit(): void {
    console.log(this.ref);
  }
}

I have tried playing with this a little bit in the repository on my machine, but I had no idea how to get the handle property from the component.

@NetanelBasal
Copy link
Member

Maybe we can register it via dialog ref

@Langstra
Copy link
Contributor Author

Tried playing around with that a little yesterday. In the same way that the resetDrag works. I could not get it to work that easily, because the dragDirective needs initializing. However, I could play around a little with it and then create a PR. Would like feedback and ideas on it if you have time to think it through a little with me.

@NetanelBasal
Copy link
Member

The dialogDraggable directive is isolated. Any reason we can't expose it and apply it to any element you want?

@Langstra
Copy link
Contributor Author

Langstra commented Aug 2, 2022

The current dialogDraggable directive needs a reference to the dialog. Currently it gets this from the dialog component, since it is applied onto this directly this is easily done by a template reference like this #dialog on the html.

@NetanelBasal
Copy link
Member

The current dialogDraggable directive needs a reference to the dialog

Where? https://github.com/ngneat/dialog/blob/master/projects/ngneat/dialog/src/lib/draggable.directive.ts

@Langstra
Copy link
Contributor Author

Langstra commented Aug 3, 2022

The dialogDragTarget needs to be a reference of string selector to the element you want to drag.

In the dialog component it is specified here. The reference is created on line 29.

https://github.com/ngneat/dialog/blob/master/projects/ngneat/dialog/src/lib/dialog.component.ts#L35

@NetanelBasal NetanelBasal added the enhancement New feature or request label Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants