File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed
src/BootstrapBlazor/Services Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -20,11 +20,6 @@ public async ValueTask SetThemeAsync(string themeName)
2020 {
2121 var module = await jsRuntime . LoadUtility ( ) ;
2222 await module . SetThemeAsync ( themeName ) ;
23-
24- if ( ThemeChangedAsync is not null )
25- {
26- await ThemeChangedAsync ( themeName ) ;
27- }
2823 }
2924
3025 /// <summary>
@@ -35,4 +30,12 @@ public async ValueTask SetThemeAsync(string themeName)
3530 var module = await jsRuntime . LoadUtility ( ) ;
3631 return await module . GetThemeAsync ( ) ;
3732 }
33+
34+ /// <summary>
35+ /// <inheritdoc/>
36+ /// </summary>
37+ public void TriggerThemeChanged ( string themeName )
38+ {
39+ ThemeChangedAsync ? . Invoke ( themeName ) ;
40+ }
3841}
Original file line number Diff line number Diff line change @@ -27,4 +27,10 @@ public interface IThemeProvider
2727 /// The callback when theme changed
2828 /// </summary>
2929 Func < string , Task > ? ThemeChangedAsync { get ; set ; }
30+
31+ /// <summary>
32+ /// Trigger the theme changed event
33+ /// </summary>
34+ /// <param name="themeName">The name of the theme to set.</param>
35+ void TriggerThemeChanged ( string themeName ) ;
3036}
Original file line number Diff line number Diff line change @@ -12,12 +12,15 @@ public async Task SetTheme_Ok()
1212 {
1313 var themeName = "" ;
1414 var themeProviderService = Context . Services . GetRequiredService < IThemeProvider > ( ) ;
15+ themeProviderService . TriggerThemeChanged ( "light" ) ;
16+
1517 themeProviderService . ThemeChangedAsync = async theme =>
1618 {
1719 themeName = theme ;
1820 await Task . CompletedTask ;
1921 } ;
2022 await themeProviderService . SetThemeAsync ( "light" ) ;
23+ themeProviderService . TriggerThemeChanged ( "light" ) ;
2124 Assert . Equal ( "light" , themeName ) ;
2225 }
2326
You can’t perform that action at this time.
0 commit comments