Last active
May 28, 2022 15:26
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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