@@ -46,57 +46,44 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
46
46
``` razor
47
47
@inject IJSRuntime JS
48
48
49
- <script suppress-error="BL9992">
50
- window.isTextOverflowing = () => {
51
- const el = document.querySelector('.example-cb .k-input-inner');
52
- if (!el) {
53
- return;
54
- }
55
-
56
- return el.scrollWidth > el.clientWidth;
57
- };
58
- </script>
59
-
60
49
@if (SelectedHobbyId != 0)
61
50
{
62
- <TelerikTooltip TargetSelector="#products-multiselect[title]"/>
51
+ <TelerikTooltip TargetSelector="#products-multiselect[title]" />
63
52
}
64
53
65
54
@{
66
- <span
67
- id="@(IsCurrentOverflowing ? "products-multiselect" : "products-multiselect-none")"
68
- @onmouseenter="OnMouseEnter"
69
- title="@CurrentHobbyName">
55
+ <span id="@(IsCurrentOverflowing ? "products-multiselect" : "products-multiselect-none")"
56
+ @onmouseenter="OnMouseEnter"
57
+ title="@CurrentHobbyName">
70
58
<TelerikComboBox @bind-Value="@SelectedHobbyId"
71
- Data="@Hobbies"
72
- Placeholder="Select your favourite sport..."
73
- TextField="@nameof(HobbiesDto.HobbyName)"
74
- ValueField="@nameof(HobbiesDto.HobbyId)"
75
- Filterable="true"
76
- Width="20%"
77
- Class="example-cb">
59
+ Data="@Hobbies"
60
+ Placeholder="Select your favourite sport..."
61
+ TextField="@nameof(HobbiesDto.HobbyName)"
62
+ ValueField="@nameof(HobbiesDto.HobbyId)"
63
+ Filterable="true"
64
+ Width="20%"
65
+ Class="example-cb">
78
66
</TelerikComboBox>
79
67
</span>
80
68
}
81
69
82
- @code {
83
- public int SelectedHobbyId { get; set; }
70
+ <script suppress-error="BL9992">
71
+ window.isTextOverflowing = () => {
72
+ const el = document.querySelector('.example-cb .k-input-inner');
73
+ if (!el) {
74
+ return;
75
+ }
76
+
77
+ return el.scrollWidth > el.clientWidth;
78
+ };
79
+ </script>
84
80
81
+ @code {
82
+ private int SelectedHobbyId { get; set; }
85
83
private bool IsCurrentOverflowing { get; set; } = false;
86
84
private string CurrentHobbyName => FindCurrentHobby()?.HobbyName;
87
85
88
- private async Task OnMouseEnter() {
89
- @if (SelectedHobbyId != 0) {
90
- IsCurrentOverflowing = await JS.InvokeAsync<bool>("isTextOverflowing");
91
- }
92
- }
93
-
94
- public HobbiesDto? FindCurrentHobby()
95
- {
96
- return Hobbies.FirstOrDefault(x => x.HobbyId == SelectedHobbyId);
97
- }
98
-
99
- public IEnumerable<HobbiesDto> Hobbies { get; set; } = new List<HobbiesDto>()
86
+ private IEnumerable<HobbiesDto> Hobbies { get; set; } = new List<HobbiesDto>()
100
87
{
101
88
new HobbiesDto(1, "This is a test for a very very very very long sentance."),
102
89
new HobbiesDto(2, "This is some long test sentance."),
@@ -106,6 +93,19 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
106
93
new HobbiesDto(6, "Football"),
107
94
};
108
95
96
+ private async Task OnMouseEnter()
97
+ {
98
+ @if (SelectedHobbyId != 0)
99
+ {
100
+ IsCurrentOverflowing = await JS.InvokeAsync<bool>("isTextOverflowing");
101
+ }
102
+ }
103
+
104
+ private HobbiesDto? FindCurrentHobby()
105
+ {
106
+ return Hobbies.FirstOrDefault(x => x.HobbyId == SelectedHobbyId);
107
+ }
108
+
109
109
public class HobbiesDto
110
110
{
111
111
public HobbiesDto(int id, string name)
@@ -122,25 +122,14 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
122
122
123
123
### MultiSelect Implementation
124
124
125
- 1 . Use the ` TagTemplate ` to customize the display of tags in the MultiSelect.
125
+ 1 . Use the [ ` TagTemplate ` ] ( slug:multiselect-templates#tag-template ) to customize the display of tags in the MultiSelect.
126
126
2 . Use JavaScript to determine overflow and set the tooltip.
127
127
128
128
> caption Display a Tooltip for Overflowing MultiSelect Items
129
129
130
130
``` razor
131
131
@inject IJSRuntime JS
132
132
133
- <script suppress-error="BL9992">
134
- window.isTextOverflowing = (id) => {
135
- const el = document.getElementById(id);
136
- if (!el) {
137
- return false;
138
- }
139
-
140
- return el.scrollWidth > el.clientWidth;
141
- };
142
- </script>
143
-
144
133
<TelerikTooltip TargetSelector=".example-ms .k-chip-label[title]">
145
134
<Template>
146
135
@{
@@ -169,21 +158,28 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
169
158
class="k-chip-label"
170
159
@onmouseenter="() => OnHoverHandler(context.HobbyId)"
171
160
id="item @context.HobbyId"
172
- title="@title ">
161
+ title="@itemTitle ">
173
162
@context.HobbyName
174
163
</span>
175
164
</span>
176
165
</TagTemplate>
177
166
</TelerikMultiSelect>
178
167
179
- @code {
180
- private async Task OnHoverHandler(int id)
181
- {
182
- IsItemOverflowing = await JS.InvokeAsync<bool>("isTextOverflowing", $"item {id}");
183
- }
168
+ <script suppress-error="BL9992">
169
+ window.isTextOverflowing = (id) => {
170
+ const el = document.getElementById(id);
171
+ if (!el) {
172
+ return false;
173
+ }
174
+
175
+ return el.scrollWidth > el.clientWidth;
176
+ };
177
+ </script>
184
178
179
+ @code {
185
180
private bool IsItemOverflowing { get; set; }
186
181
private List<int> SelectedHobbyIds { get; set; }
182
+
187
183
private IEnumerable<HobbiesDto> Hobbies { get; set; } = new List<HobbiesDto>()
188
184
{
189
185
new HobbiesDto(1, "This is a test for a very very very very long sentance."),
@@ -194,6 +190,11 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
194
190
new HobbiesDto(6, "Football"),
195
191
};
196
192
193
+ private async Task OnHoverHandler(int id)
194
+ {
195
+ IsItemOverflowing = await JS.InvokeAsync<bool>("isTextOverflowing", $"item {id}");
196
+ }
197
+
197
198
public class HobbiesDto
198
199
{
199
200
public int HobbyId { get; set; }
@@ -217,6 +218,6 @@ To ensure tooltips are displayed only when text is ellipsed, use JavaScript to c
217
218
218
219
- [ ComboBox Overview] ( slug:components/combobox/overview )
219
220
- [ MultiSelect Overview] ( slug:multiselect-overview )
220
- - [ Tooltip Configuration ] ( slug:tooltip-overview )
221
+ - [ Tooltip Overview ] ( slug:tooltip-overview )
221
222
- [ JavaScript scrollWidth Documentation] ( https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollWidth )
222
223
- [ JavaScript clientWidth Documentation] ( https://developer.mozilla.org/en-US/docs/Web/API/Element/clientWidth )
0 commit comments