Tooltip on the selected item (not on the searching list)
See original GitHub issueIs your feature request related to a problem? Please describe. I need to see the title for the selected option, because usually the text is too long to be shown on a small input size.
Describe the solution you’d like I want to put title attribute (tooltip) for the selected item from the list to see the tooltip while mouse is over the ng-select input.
Additional context
<ng-select
[items]="bookkeepingAccounts | async"
formControlName="bookkeepingAccount"
[searchFn]="searchBookkeepingAccount"
(change)="bookkeepingAccountChanged($event)"
required>
<ng-template ng-label-tmp let-item="item">
<span> [title]="item.title">{{ item.code }} {{ item.title }}</span> // <-- this DOES NOT work
</ng-template>
<ng-template ng-option-tmp let-item="item">
<span [title]="item.title"> // <-- but this DOES work
{{ item.code }} <br />
<small>{{ item.title }}</small>
</span>
</ng-template>
</ng-select>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Show tooltip when selecting item on asp:DropDownList
I have an asp:DropDownList on a page that, due to the 1024x768 development standard can truncate some of the text values in the...
Read more >List View Search tooltip gives users the impression that certain ...
List View Search tooltip gives users the impression that certain fields aren't searchable. Search , Lightning.
Read more >How to set Tool tip to dropdown list in each item select or ...
You can do it on the selected item in the ListBox. Not sure if the options will react to the mouse events by...
Read more >How to show tooltip for display value of Select List (item type)?
Hi all, APEX 18.2, database 19 EE Is it possible to show a tooltip for the display value when opening a select list...
Read more >javascript to show the selected item of dropdown in tooltip
If you don't consider the users who are using IE 6.0, the solution is to set title attribute for each list item. If...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey! I think this issue lacks a demo page. I’ve prepared one: https://stackblitz.com/edit/ng-select-items-tooltip
On this demo page you can see that generally it is possible to add a tooltip both for select options and the selected value. There is only one problem I’m concerned with: for single-selection ng-select’s, the selected item tooltip doesn’t show up.
It happens because, due to the way single-selection ng-select’s are designed, the selected item label is obscured by a transparent input box that intercepts clicks:
In order for the tooltip to show up, it has to applied to the
.ng-value-container
element rather than the selected item label. But ng-select is not customizable at that level, which is understandable:This HTML code, taken from ng-select implementation, is fairly large and complicated, so hardly any of ng-select users would want to duplicate it in their application code in order to apply customizations. And as far as I see, such duplication cannot be avoided. If Angular allowed content projection / transclusion not only in component templates, but in all templates, ng-select’s template could be implemented like this:
…but at the moment it is not possible.
Alternatively ng-select could provide tooltips out of the box, but it also feels like a bad solution to me. Some ng-select users would want a matTooltip, others—a plain
title
attribute etc. It would be unreasonable for ng-select to support all of these options.I am currently going to try out the following approach: implement an Angular directive in the application code that would add a
title
attribute to the.ng-value-container
element. This approach comes with a few problems:title
attribute. That is, one wouldn’t be able to inject a fully-fledged tooltip component like matTooltip.But despite these limitations, I think this approach will work for us.
Update: There you go:
@earshinov how it can be done when it is a reusable component like the following example, where there are no html tags like div, span, etc.
<ng-select [items]=“collection” [appendTo]=“container” [placeholder]=“placeholder!” [multiple]=“multiple” [formControl]=“formControl” [bindLabel]=“getTextProperty()!” (blur)=“handleBlur()” (click)=“$event.stopPropagation()” > <ng-template *ngIf=“labelTemplate” ng-label-tmp let-item=“item” let-clear=“clear”> <ng-container *ngTemplateOutlet=“labelTemplate; context: { item: item, clear: clear }”></ng-container> </ng-template> <ng-template *ngIf=“optionTemplate” ng-option-tmp let-item=“item”> <ng-container *ngTemplateOutlet=“optionTemplate; context: { item: item }”></ng-container> </ng-template> </ng-select>