File tree Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Expand file tree Collapse file tree 3 files changed +25
-11
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,13 @@ public static async Task GoBackAsync(this IJSRuntime jsRuntime)
10
10
11
11
public static async Task NavigateTo ( this IJSRuntime jsRuntime , string newUrl )
12
12
=> await jsRuntime . InvokeVoidAsyncWithErrorHandling ( "utilities.updatePathAndQueryString" , newUrl ) ;
13
-
13
+ public static async ValueTask < bool > ScrollToBottomOfElement ( this IJSRuntime jsRuntime , string selector ) => await jsRuntime . InvokeVoidAsyncWithErrorHandling (
14
+ "scrollFunctions.scrollToBottomOfElement" ,
15
+ selector ) ;
16
+ public static async Task < bool > HideElement ( this IJSRuntime jsRuntime , string selector )
17
+ => await jsRuntime . InvokeVoidAsyncWithErrorHandling (
18
+ "utilities.hideElement" ,
19
+ selector ) ;
14
20
public static async ValueTask < GeoLocation ? > GetGeolocation ( this IJSRuntime jsRuntime )
15
21
{
16
22
var ( success , geoLocation ) = await jsRuntime . InvokeAsyncWithErrorHandling < GeoLocation > ( "utilities.getGeolocation" ) ;
Original file line number Diff line number Diff line change 33
33
<MudText Typo =" Typo.h5" >@ActiveChat.GetDisplayName(CurrentUser.Id ! )</MudText >
34
34
</MudAppBar >
35
35
}
36
-
37
- <MudList Class =" chat-message-list" Padding =" false" ReadOnly Dense T =" RenderFragment" >
36
+
37
+ @* The elements below cannot be readonly/disabled, as it disabled the tooltips *@
38
+ <MudList Class =" chat-message-list" Padding =" false" Dense T =" RenderFragment" >
38
39
<MudSpacer />
39
40
<MudVirtualize Items =" ActiveChat?.Messages" Context =" message" OverscanCount =" 8" ItemSize =" 80" >
40
41
96
97
AdornmentIcon =" @Icons.Material.Filled.Send"
97
98
AdornmentColor =" @(string.IsNullOrWhiteSpace(_messageInput.Value) ? Color.Default : Color.Primary)"
98
99
OnAdornmentClick =" SendMessage"
99
- Class =" mt-3"
100
- Lines =" 3 "
100
+ Class =" mt-3 p-1 "
101
+ Lines =" 2 "
101
102
IconSize =" Size.Large"
102
103
Style =" @($" background: {JordnaerTheme.CustomTheme.PaletteLight.BackgroundGray} " )" />
103
104
</MudList >
162
163
163
164
protected override async Task OnAfterRenderAsync (bool firstRender )
164
165
{
165
- await ScrollToBottom ( );
166
+ await JsRuntime . ScrollToBottomOfElement ( " .chat-message-window " );
166
167
}
167
168
168
169
private void MarkMessageIfSuccessfullySentByCurrentUser ()
182
183
LastMessageWasSentSuccessfullyByCurrentUser = lastMessage .SenderId == CurrentUser .Id ;
183
184
}
184
185
185
- private async ValueTask ScrollToBottom () => await JsRuntime .InvokeVoidAsyncWithErrorHandling (" scrollFunctions.scrollToBottomOfElement" , " .chat-message-window" );
186
-
187
186
private async Task BackToList ()
188
187
{
189
188
ActiveChat = null ;
222
221
}
223
222
224
223
await _messageInput .FocusAsync ();
225
- await ScrollToBottom ( );
224
+ await JsRuntime . ScrollToBottomOfElement ( " .chat-message-window " );
226
225
}
227
226
228
227
// TODO: Add MudScrollToTop that shows when user is scrolled up in the chat window
Original file line number Diff line number Diff line change @@ -21,8 +21,17 @@ window.scrollFunctions = {
21
21
scrollToBottomOfElement : function ( selector ) {
22
22
const element = document . querySelector ( selector ) ;
23
23
24
- if ( ! element ) return ;
24
+ if ( ! element ) {
25
+ return ;
26
+ }
25
27
26
- element . scrollTop = element . scrollHeight ;
28
+ // Ensure the element is fully rendered before scrolling
29
+ setTimeout ( function ( ) {
30
+ element . scrollTo ( {
31
+ top : element . scrollHeight ,
32
+ left : 0 ,
33
+ behavior : 'instant' // 'auto', 'instant' or 'smooth' (default is 'auto')
34
+ } ) ;
35
+ } , 50 ) ; // Adjust the delay as needed
27
36
}
28
37
} ;
You can’t perform that action at this time.
0 commit comments