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

Can I attach an OverlayPanel to something else than a button? #324

Open
JPGygax68 opened this issue Jul 25, 2019 · 3 comments
Open

Can I attach an OverlayPanel to something else than a button? #324

JPGygax68 opened this issue Jul 25, 2019 · 3 comments

Comments

@JPGygax68
Copy link

JPGygax68 commented Jul 25, 2019

I'm trying to attach an OverlayPanel to a tl-input: Stackblitz

The panel does open, but it appears to be attached to the body element instead of the tl-input.

When attaching it to a tl-button as per your docs, it does work (see commented code in the html). Even then though, there seems to be something wrong with the panel, it has no background color.

@WilliamAguera
Copy link
Member

Sorry for the docs, we are implementing a new one and updating them, the [color] property doesn't exist anymore on TlOverlayPanel. To do this you just style your wrapper div to your wished color.

The OverlayPanel uses overlay of angular/cdk so we have get an ElementRef to attach. When you hastag a component inside of HTML, angular pass the instance of that component. As a workaround to that, you can do this:

@ViewChild('inputField', { read: ElementRef, static: true }) input: ElementRef;

Then, pass the input variable to [elementOrigin] property.

I updated the stackblitz and we are updating the docs as soon as possible.
https://stackblitz.com/edit/truly-ui-simple-7lqc5a

Close this issue as your doubts are answered.

Thank you for using truly-ui an helping to improve it.

@JPGygax68
Copy link
Author

Thank you @WilliamAguera, the workaround works.

Are you planning to generalize elementOrigin to support some of your other components too?

@JPGygax68
Copy link
Author

I found that the overlay panel that opens below my input field does not have the same width as the input field, and found the following workaround:

@ViewChild('inputField', { static: true }) inputFieldRef; // : TlInput;
@ViewChild('inputField', { read: ElementRef, static: true }) inputFieldElem: ElementRef;
@ViewChild('browsingPanel', { static: true }) browsingPanelRef; // : TlOverlayPanel;

...

// (clickAddon) event on the TlInput
onClickAddon() {
    this.browsingPanelRef.width = this.inputFieldElem.nativeElement.firstChild.offsetWidth + 'px';
    this.browsingPanelRef.toggle();
  }

Is there a better way?

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

No branches or pull requests

3 participants