I'm refactoring a directive which adds some sort of a tooltip over the form controls on mouse hover/focus. It's simple to use. Just add it to the element and define its text. The input you use for the text also defines the tooltip's styling
<!-- Creates red tooltip -->
<input matInput type="text" libMessage [libError]="'Error Text'" />
<!-- Creates blue tooltip -->
<input matInput type="text" libMessage [libInfo]="'Info Text'" />
<!-- Creates yellow tooltip -->
<input matInput type="text" libMessage [libWarning]="'Warning Text'" />
We received a request to extend it with option to display not just the text, but also a custom component, which provides better options for styling. It works but it feels bit cumbersome. Instead of just providing a component you have to specify it's type by providing [libError] value with non-empty string.
<!-- Creates red tooltip from simple text -->
<input matInput type="text" libMessage [libError]="'Error Text'" />
<!-- Creates a tooltip from component with red background. Text is ignored. -->
<input matInput type="text" libMessage [libError]="'Error Text'" [libCustomComponent]="someComponent" />
I came with couple of workarounds but was wondering if it's possible to have a directive's input working in two ways. As the Input and the Attribute at the same time. If used with value, it defines the text, if used alone, it defines style but the component has to be provided. Something like this.
<!-- [libError] specifies the text and type -->
<input matInput type="text" libMessage [libError]="'Error Text'" />
<!-- libError defines just a style, no value is needed. -->
<input matInput type="text" libMessage libError [libCustomComponent]="someComponent" />
Is it possible to do something like this?