1
+ <style >
2
+ .can-drop {
3
+ border : 2px dashed green ;
4
+ }
5
+ </style >
6
+ <div >
7
+ <InputTextArea
8
+ @attributes =" AdditionalAttributes"
9
+ class =" @_cssClass"
10
+ @bind-Value =" @BindingValue"
11
+ ondragover =" event.stopPropagation(); event.preventDefault();"
12
+ ondragstart =" event.stopPropagation(); event.preventDefault();"
13
+ ondragexit =" event.stopPropagation(); event.preventDefault();"
14
+ ondragend =" event.stopPropagation(); event.preventDefault();"
15
+ @ondrop =" HandleDrop"
16
+ @ondragenter =" HandleDragEnter"
17
+ @ondragleave =" HandleDragLeave" />
18
+ </div >
19
+
20
+ @code {
21
+ private string _dropClass = string .Empty ;
22
+ private string _otherClasses = string .Empty ;
23
+ private string _cssClass => _dropClass + " " + _otherClasses ;
24
+
25
+ private string _value ;
26
+
27
+ [Parameter ]
28
+ public string BindingValue
29
+ {
30
+ get => _value ;
31
+ set
32
+ {
33
+ if (_value == value ) return ;
34
+ _value = value ;
35
+ BindingValueChanged .InvokeAsync (value );
36
+ }
37
+ }
38
+
39
+ [Parameter ]
40
+ public EventCallback <string > BindingValueChanged { get ; set ; }
41
+
42
+ [Parameter (CaptureUnmatchedValues = true )]
43
+ public IReadOnlyDictionary <string , object > AdditionalAttributes { get ; set ; }
44
+
45
+ protected override void OnParametersSet ()
46
+ {
47
+ if (AdditionalAttributes != null && AdditionalAttributes .ContainsKey (" class" ))
48
+ {
49
+ _otherClasses = AdditionalAttributes [" class" ].ToString ();
50
+ }
51
+ }
52
+
53
+ private void HandleDrop (DragEventArgs args )
54
+ {
55
+ _dropClass = string .Empty ;
56
+ // // This will only work with .NET 6
57
+ // var files = args.DataTransfer.Files;
58
+ }
59
+
60
+ private void HandleDragEnter ()
61
+ {
62
+ _dropClass = " can-drop" ;
63
+ }
64
+
65
+ private void HandleDragLeave ()
66
+ {
67
+ _dropClass = string .Empty ;
68
+ }
69
+ }
0 commit comments