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

Input reference to container element for mwlDraggable #1696

Open
paolosanchi opened this issue Nov 13, 2023 · 1 comment
Open

Input reference to container element for mwlDraggable #1696

paolosanchi opened this issue Nov 13, 2023 · 1 comment

Comments

@paolosanchi
Copy link

Is your feature request related to a problem? Please describe

I need to populate the following property for both mwlDraggable and mwlDroppable.

@Optional() private scrollContainer: DraggableScrollContainerDirective

Currently it can be done by placing the mwlDraggableScrollContainer directive on the scrolling element.
Using Ionic, my issue is that the scrolling element is not accessible because it is nested in a shadow-root and managed by ion-content. Because of this I can't add any directive to it (I guess).
What I can do, is to get a reference to the scrolling element like already did with the following:

<ion-content #content>
    <div mwlDraggable [ghostElementAppendTo]="$any(content).el"></div>
</ion-content>

Describe the solution you'd like

I'd like to pass the scrollable element to do the mwlDraggableScrollContainer like this:

<ion-content #content mwlDraggableScrollContainer="$any(content).el">
    <div mwlDraggable [ghostElementAppendTo]="$any(content).el"></div>
</ion-content>

Describe your use case for implementing this feature

I guess something like this would do the trick:

@Directive({
  selector: '[mwlDraggableScrollContainer]',
})
export class DraggableScrollContainerDirective {

  @Input() mwlDraggableScrollContainer: HTMLElement;

  /**
   * @hidden
   */
  constructor(public elementRef: ElementRef<HTMLElement>) {}

  ngOnInit(){
    this.elementRef ||= new ElementRef(this.mwlDraggableScrollContainer);
  }
}

maybe it's a better idea to place it in ngOnChange.

By the way, it seems to currently work with this tricky solution:

<ion-content #content mwlDraggableScrollContainer [scrollEvents]="true" (ionScroll)="emitScrollEvent(content)">
</ion-content>

emitScrollEvent(content: IonContent) {
  const element = (content as any).el as HTMLElement;
  element.dispatchEvent(new CustomEvent('scroll'));
}
@matts-bot
Copy link

matts-bot bot commented Nov 13, 2023

Thanks so much for opening an issue! If you'd like to support this project, then please consider sponsoring me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant