@@ -69,29 +69,30 @@ Replace `YourAppName` with the actual root namespace of your app.
6969<h1>InPlaceEditor Component</h1>
7070
7171<p>
72- This in-place editor component works with multiple value types and nullables
72+ This in-place editor component works with value types, including nullables
7373
7474 <TelerikInPlaceEditor @bind-Value="@NumericValue"
7575 DisplayFormat="C2"
7676 Placeholder="Enter Number..." />
7777
78- The component can apply custom CSS styles and the icon can be visible only on hover
78+ The component supports custom styles
7979
8080 <TelerikInPlaceEditor @bind-Value="@StringValue"
8181 Class="primary-color"
8282 ShowIcon="@InPlaceEditorShowIcon.Hover" />
8383
84- (unless the value is empty) or hidden at all times
84+ and the icon can be visible only on hover
8585
8686 <TelerikInPlaceEditor @bind-Value="@DateValue"
8787 Class="primary-color"
8888 DisplayFormat="d"
89- ShowIcon="@InPlaceEditorShowIcon.Never " />
89+ ShowIcon="@InPlaceEditorShowIcon.Hover " />
9090
91- The editor width is calculated automatically if not set
91+ (unless the value is empty) or never
9292
9393 <TelerikInPlaceEditor @bind-Value="@TimeValue"
94- DisplayFormat="HH:mm" />
94+ DisplayFormat="HH:mm"
95+ ShowIcon="@InPlaceEditorShowIcon.Never" />
9596
9697 You can even edit booleans
9798
@@ -202,7 +203,7 @@ Replace `YourAppName` with the actual root namespace of your app.
202203
203204@code {
204205 private bool BoolValue { get; set; }
205- private DateTime DateValue { get; set; } = DateTime.Now;
206+ private DateTime? DateValue { get; set; } = DateTime.Now;
206207 private decimal? NumericValue { get; set; } = 1.23m;
207208 private string StringValue { get; set; } = "foo bar";
208209 private TimeOnly TimeValue { get; set; } = TimeOnly.FromDateTime(DateTime.Now);
@@ -234,7 +235,7 @@ Replace `YourAppName` with the actual root namespace of your app.
234235
235236@typeparam T
236237
237- <span class="@ClassToRender">
238+ <span class="@ClassToRender" @onkeydown="@OnSpanKeyDown" >
238239 @if (IsInEditMode)
239240 {
240241 switch (ValueEditorType)
@@ -293,7 +294,7 @@ Replace `YourAppName` with the actual root namespace of your app.
293294 }
294295 else if (!ReadOnly)
295296 {
296- <TelerikButton Class="@ButtonClass "
297+ <TelerikButton Class="@EditButtonClass "
297298 FillMode="@ThemeConstants.Button.FillMode.Clear"
298299 OnClick="@ToggleEditMode"
299300 Title="@Title">
@@ -308,7 +309,7 @@ Replace `YourAppName` with the actual root namespace of your app.
308309
309310 @if (ShouldRenderEditIcon)
310311 {
311- <TelerikSvgIcon Icon="@SvgIcon.Pencil" Class="@IconClass " />
312+ <TelerikSvgIcon Icon="@SvgIcon.Pencil" Class="@EditIconClass " />
312313 }
313314 </TelerikButton>
314315 }
@@ -388,7 +389,9 @@ Replace `YourAppName` with the actual root namespace of your app.
388389 private const string InPlaceEditorClass = "in-place-editor";
389390 private const string CheckBoxClass = "in-place-checkbox";
390391 private const string ButtonClass = "in-place-button";
391- private const string IconHoverableClass = "hoverable-icon";
392+ private const string EditButtonClass = $"{ButtonClass} in-place-edit-button";
393+ private const string IconClass = "in-place-icon";
394+ private const string IconHoverableClass = $"{IconClass} in-place-hoverable-icon";
392395 private const string InputClass = "in-place-input";
393396 private const string PlaceholderClass = "in-place-placeholder";
394397
@@ -398,6 +401,8 @@ Replace `YourAppName` with the actual root namespace of your app.
398401
399402 private readonly string DataId = Guid.NewGuid().ToString();
400403
404+ private T? OriginalEditValue { get; set; }
405+
401406 private Type ValueType { get; set; } = typeof(string);
402407
403408 private InPlaceEditorType ValueEditorType { get; set; } = InPlaceEditorType.TextBox;
@@ -410,7 +415,7 @@ Replace `YourAppName` with the actual root namespace of your app.
410415
411416 private string ClassToRender => string.Format("{0} {1}", InPlaceEditorClass, Class);
412417
413- private string IconClass => ShowIcon == InPlaceEditorShowIcon.Hover && GetFormattedValue().Length > 0 ? IconHoverableClass : string.Empty ;
418+ private string EditIconClass => ShowIcon == InPlaceEditorShowIcon.Hover && GetFormattedValue().Length > 0 ? IconHoverableClass : IconClass ;
414419
415420 #endregion Properties
416421
@@ -436,6 +441,20 @@ Replace `YourAppName` with the actual root namespace of your app.
436441
437442 #region Methods
438443
444+ private async Task OnSpanKeyDown(KeyboardEventArgs args)
445+ {
446+ if (args.Key == "Escape")
447+ {
448+ Value = OriginalEditValue;
449+ IsInEditMode = false;
450+
451+ if (ValueChanged.HasDelegate)
452+ {
453+ await ValueChanged.InvokeAsync(Value);
454+ }
455+ }
456+ }
457+
439458 private string GetEditorWidth(InPlaceEditorType editorType)
440459 {
441460 if (!string.IsNullOrEmpty(Width))
@@ -464,6 +483,7 @@ Replace `YourAppName` with the actual root namespace of your app.
464483
465484 if (IsInEditMode)
466485 {
486+ OriginalEditValue = Value;
467487 ShouldFocusEditor = true;
468488 }
469489 }
@@ -474,7 +494,7 @@ Replace `YourAppName` with the actual root namespace of your app.
474494 {
475495 return Convert.ToDouble(Value).ToString(DisplayFormat);
476496 }
477- else if (ValueType == typeof(DateTime) || ValueType == typeof(DateOnly))
497+ else if (( ValueType == typeof(DateTime) || ValueType == typeof(DateOnly)) && Value != null )
478498 {
479499 return Convert.ToDateTime(Value).ToString(DisplayFormat);
480500 }
@@ -598,32 +618,34 @@ Replace `YourAppName` with the actual root namespace of your app.
598618 }
599619}
600620````
601- ```` InPlaceEditor .razor.css
621+ ```` TelerikInPlaceEditor .razor.css
602622.in-place-editor {
623+ display : inline-flex ;
603624 font-family : monospace ;
604625}
605626
606627::deep .in-place-checkbox {
607628 margin-inline : 1em ;
608629}
609630
610- ::deep .in-place-button {
631+ ::deep .in-place-button ,
632+ ::deep .in-place-icon {
611633 color : inherit ;
612634}
613635
614- ::deep .in-place-button .k- icon {
615- margin-inline-start : .4 em ;
636+ ::deep .in-place-icon {
637+ margin-inline-start : .5 em ;
616638}
617639
618- ::deep .in-place-button . hoverable-icon {
640+ ::deep .in-place-hoverable-icon {
619641 display : none ;
620642}
621643
622- ::deep .in-place-button :hover {
644+ ::deep .in-place-edit- button :hover {
623645 background-color : var (--kendo-color-base ) !important ;
624646}
625647
626- ::deep .in-place-button :hover .hoverable-icon {
648+ ::deep .in-place-edit- button :hover .in-place- hoverable-icon {
627649 display : inline-flex ;
628650 }
629651
0 commit comments