@@ -25,12 +25,11 @@ public MudSelectExtended()
25
25
IconSize = Size . Medium ;
26
26
}
27
27
28
- [ Inject ] private IKeyInterceptorFactory ? KeyInterceptorFactory { get ; set ; }
28
+ [ Inject ] private IKeyInterceptorService KeyInterceptorService { get ; set ; } = null ! ;
29
29
30
30
private MudListExtended < T ? > ? _list ;
31
31
private bool _dense ;
32
32
private string ? multiSelectionText ;
33
- private IKeyInterceptor ? _keyInterceptor ;
34
33
/// <summary>
35
34
/// The collection of items within this select
36
35
/// </summary>
@@ -776,8 +775,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
776
775
777
776
if ( firstRender )
778
777
{
779
- _keyInterceptor = KeyInterceptorFactory ? . Create ( ) ;
780
- await _keyInterceptor . Connect ( _elementId , new KeyInterceptorOptions ( )
778
+ // TODO: Make HandleKeyDown / HandleKeyUp async Task
779
+ await KeyInterceptorService . SubscribeAsync ( _elementId , new KeyInterceptorOptions ( )
781
780
{
782
781
//EnableLogging = true,
783
782
TargetClass = "mud-input-control" ,
@@ -794,9 +793,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
794
793
new KeyOptions { Key = "A" , PreventDown = "key+ctrl" } , // select all items instead of all page text
795
794
new KeyOptions { Key = "/./" , SubscribeDown = true , SubscribeUp = true } , // for our users
796
795
} ,
797
- } ) ;
798
- _keyInterceptor . KeyDown += HandleKeyDown ;
799
- _keyInterceptor . KeyUp += HandleKeyUp ;
796
+ } , keyDown : HandleKeyDown , keyUp : HandleKeyUp ) ;
800
797
await UpdateTextPropertyAsync ( false ) ;
801
798
_list ? . ForceUpdateItems ( ) ;
802
799
SelectedListItem = Items . FirstOrDefault ( x => x . Value != null && Value != null && x . Value . Equals ( Value ) ) ? . ListItem ;
@@ -824,12 +821,11 @@ protected override void Dispose(bool disposing)
824
821
825
822
if ( disposing )
826
823
{
827
- if ( _keyInterceptor != null )
824
+ if ( IsJSRuntimeAvailable )
828
825
{
829
- _keyInterceptor . KeyDown -= HandleKeyDown ;
830
- _keyInterceptor . KeyUp -= HandleKeyUp ;
826
+ //TODO: Use IAsyncDisposable instead.
827
+ KeyInterceptorService . UnsubscribeAsync ( _elementId ) . CatchAndLog ( ) ;
831
828
}
832
- _keyInterceptor ? . Dispose ( ) ;
833
829
}
834
830
}
835
831
@@ -1012,7 +1008,7 @@ public async Task OpenMenu()
1012
1008
StateHasChanged ( ) ;
1013
1009
1014
1010
//disable escape propagation: if selectmenu is open, only the select popover should close and underlying components should not handle escape key
1015
- await _keyInterceptor . UpdateKey ( new ( ) { Key = "Escape" , StopDown = "Key+none" } ) ;
1011
+ await KeyInterceptorService . UpdateKeyAsync ( _elementId , new ( ) { Key = "Escape" , StopDown = "Key+none" } ) ;
1016
1012
await OnOpen . InvokeAsync ( ) ;
1017
1013
}
1018
1014
@@ -1034,7 +1030,7 @@ public async Task CloseMenu()
1034
1030
//}
1035
1031
1036
1032
//enable escape propagation: the select popover was closed, now underlying components are allowed to handle escape key
1037
- await _keyInterceptor . UpdateKey ( new ( ) { Key = "Escape" , StopDown = "none" } ) ;
1033
+ await KeyInterceptorService . UpdateKeyAsync ( _elementId , new ( ) { Key = "Escape" , StopDown = "none" } ) ;
1038
1034
1039
1035
await OnClose . InvokeAsync ( ) ;
1040
1036
}
0 commit comments