Skip to content

Instantly share code, notes, and snippets.

@dorthrithil
Last active May 28, 2022 15:26
Show Gist options
  • Save dorthrithil/bf87f8c7bdd987aa5f211b2a73ecae19 to your computer and use it in GitHub Desktop.
Save dorthrithil/bf87f8c7bdd987aa5f211b2a73ecae19 to your computer and use it in GitHub Desktop.
Prevent Clarity Angular dropdown clipping - Directive that prevents clipping of Clarity dropdowns (maybe also popovers etc. - not tested) when they are inside * containers that hide overflow. The trick is to just detach the element and attach it to the body.
/**
* Directive that prevents clipping of Clarity dropdowns (maybe also popovers etc. - not tested) when they are inside
* containers that hide overflow. The trick is to just detach the element and attach it to the body.
* Use it like this on the element that is clipping:
*
* ```
* <clr-dropdown-menu clrPosition="bottom-left" appAntiClipping>
* ```
*/
@Directive({
selector: '[appAntiClipping]'
})
export class AntiClippingDirective implements OnInit {
constructor(private el: ElementRef,
@Inject(DOCUMENT) private document: Document) {
}
/**
* De- and attaches the element to prevent clipping issues.
*/
ngOnInit() {
this.el.nativeElement.parentNode.removeChild(this.el.nativeElement);
this.document.body.appendChild(this.el.nativeElement);
this.el.nativeElement.style.visibility = 'visible';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment