+ }
+
+ @{
+ var startTime = new DateTime(2020, 1, 1, 0, 0, 0);
+ var timeFormat = DatePicker.ShowTimeFormat;
+
+ if (Picker == AntDatePickerType.Time && !string.IsNullOrEmpty(DatePicker.Format))
{
-
+ timeFormat = DatePicker.Format;
}
- @{
- var startTime = new DateTime(2020, 1, 1, 0, 0, 0);
- var timeFormat = DatePicker.ShowTimeFormat;
-
- if (Picker == AntDatePickerType.Time && !string.IsNullOrEmpty(DatePicker.Format))
- {
- timeFormat = DatePicker.Format;
- }
-
- AntDatePickerDisabledTime disabledTime = GetDisabledTime();
- }
-
-
-
- @if (timeFormat.ToLower().Contains("hh"))
- {
-
- }
- @if (timeFormat.ToLower().Contains("mm"))
- {
-
- }
- @if (timeFormat.ToLower().Contains("ss"))
- {
-
- }
+ AntDatePickerDisabledTime disabledTime = GetDisabledTime();
+ }
+
+
+
+ @if (timeFormat.ToLower().Contains("hh"))
+ {
+
+ }
+ @if (timeFormat.ToLower().Contains("mm"))
+ {
+
+ }
+ @if (timeFormat.ToLower().Contains("ss"))
+ {
+
+ }
+
+
@if (DatePicker.RenderExtraFooter != null)
{
diff --git a/components/date-picker/internal/AntDatePickerPanelBase.cs b/components/date-picker/internal/AntDatePickerPanelBase.cs
index dfbd8c98e..ab148b692 100644
--- a/components/date-picker/internal/AntDatePickerPanelBase.cs
+++ b/components/date-picker/internal/AntDatePickerPanelBase.cs
@@ -115,7 +115,7 @@ namespace AntBlazor
protected DateTime PickerValue { get => DatePicker.GetIndexPickerValue(PickerIndex); }
- protected DateTime Value { get => DatePicker.GetIndexValue(PickerIndex); }
+ protected DateTime Value { get => DatePicker.GetIndexValue(PickerIndex) ?? DateTime.Now; }
public void PopUpPicker(string type)
{
diff --git a/components/dropdown/AntDropdown.razor.cs b/components/dropdown/AntDropdown.razor.cs
index 61279e838..d699abb31 100644
--- a/components/dropdown/AntDropdown.razor.cs
+++ b/components/dropdown/AntDropdown.razor.cs
@@ -215,5 +215,15 @@ namespace AntBlazor
return false;
}
+
+ public async Task Show()
+ {
+ await _antDropdownOverlay.Show();
+ }
+
+ public async Task Hide()
+ {
+ await _antDropdownOverlay.Hide();
+ }
}
}
diff --git a/components/dropdown/internal/AntDropdownOverlay.razor b/components/dropdown/internal/AntDropdownOverlay.razor
index 5a20a7baf..f2484ef7c 100644
--- a/components/dropdown/internal/AntDropdownOverlay.razor
+++ b/components/dropdown/internal/AntDropdownOverlay.razor
@@ -4,10 +4,10 @@
@if (_hasAddOverlayToBody == true || _isWaitForOverlayFirstRender)
{
- string display = Dropdown.Visible ? "" : "visibility: hidden;";
+ string display = _isOverlayShow ? "" : "visibility: hidden;";
string overlayCls;
- if (!Dropdown.Visible && !_isWaitForOverlayFirstRender)
+ if (!_isOverlayShow && !_isWaitForOverlayFirstRender)
{
overlayCls = $"{Dropdown.PrefixCls}-hidden";
display = "";
diff --git a/components/dropdown/internal/AntDropdownOverlay.razor.cs b/components/dropdown/internal/AntDropdownOverlay.razor.cs
index 5b951d46c..23391f6ee 100644
--- a/components/dropdown/internal/AntDropdownOverlay.razor.cs
+++ b/components/dropdown/internal/AntDropdownOverlay.razor.cs
@@ -23,6 +23,9 @@ namespace AntBlazor.Internal
private bool _isOverlayFirstRender = true;
private bool _isWaitForOverlayFirstRender = false;
+ private bool _preVisible = false;
+ private bool _isOverlayShow = false;
+
private int? _overlayLeft = null;
private int? _overlayTop = null;
@@ -31,6 +34,21 @@ namespace AntBlazor.Internal
private const int OVERLAY_TOP_OFFSET = 4;
+ protected override async Task OnParametersSetAsync()
+ {
+ if (!_isOverlayShow && Dropdown.Visible && !_preVisible)
+ {
+ await Show(_overlayLeft, _overlayTop);
+ }
+ else if (_isOverlayShow && !Dropdown.Visible && _preVisible)
+ {
+ await Hide();
+ }
+
+ _preVisible = Dropdown.Visible;
+ await base.OnParametersSetAsync();
+ }
+
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
@@ -41,29 +59,18 @@ namespace AntBlazor.Internal
{
await JsInvokeAsync(JSInteropConstants.addClsToFirstChild, Ref, $"disabled");
}
-
- if (Dropdown.Visible)
- {
- await Show(_overlayLeft, _overlayTop);
-
- _overlayLeft = null;
- _overlayTop = null;
- }
}
- else
+
+ if (_isWaitForOverlayFirstRender && _isOverlayFirstRender)
{
- if (_isWaitForOverlayFirstRender && _isOverlayFirstRender)
- {
- _isOverlayFirstRender = false;
+ _isOverlayFirstRender = false;
- await Show(_overlayLeft, _overlayTop);
+ await Show(_overlayLeft, _overlayTop);
- _isWaitForOverlayFirstRender = false;
- _overlayLeft = null;
- _overlayTop = null;
- }
+ _isWaitForOverlayFirstRender = false;
+ _overlayLeft = null;
+ _overlayTop = null;
}
-
await base.OnAfterRenderAsync(firstRender);
}
@@ -86,7 +93,7 @@ namespace AntBlazor.Internal
public async Task Show(int? overlayLeft = null, int? overlayTop = null)
{
- if (Dropdown.Visible || Dropdown.Disabled)
+ if (_isOverlayShow || Dropdown.Disabled)
{
return;
}
@@ -102,7 +109,7 @@ namespace AntBlazor.Internal
return;
}
- Dropdown.Visible = true;
+ _isOverlayShow = true;
await AddOverlayToBody();
@@ -124,7 +131,7 @@ namespace AntBlazor.Internal
public async Task Hide(bool force = false)
{
- if (!Dropdown.Visible)
+ if (!_isOverlayShow)
{
return;
}
@@ -147,7 +154,7 @@ namespace AntBlazor.Internal
// wait for leave animation
await Task.Delay(200);
- Dropdown.Visible = false;
+ _isOverlayShow = false;
StateHasChanged();
}
@@ -159,7 +166,7 @@ namespace AntBlazor.Internal
public bool IsPopup()
{
- return Dropdown.Visible;
+ return _isOverlayShow;
}
private async Task AddOverlayToBody()
diff --git a/site/AntBlazor.Docs/Pages/DatePicker.razor b/site/AntBlazor.Docs/Pages/DatePicker.razor
index cba4420d3..667afacc7 100644
--- a/site/AntBlazor.Docs/Pages/DatePicker.razor
+++ b/site/AntBlazor.Docs/Pages/DatePicker.razor
@@ -5,68 +5,68 @@
演示
-
+
基本
最简单的用法,在浮层中可以选择或者输入日期。
-
-
-
-
-
+
+
+
+
+
-
+
范围选择器
通过设置 Picker 属性,指定范围选择器类型。
-
-
-
-
-
+
+
+
+
+
-
+
禁用
选择框的不可用状态。你也可以通过数组单独禁用 RangePicker 的其中一项。
-
+
-
+
日期格式
使用 Format 可以自定义日期显示格式。
-
-
+
+
-
+
日期时间选择
增加选择时间功能,当 ShowTime 为一个对象时,其属性会传递给内建的 TimePicker。
-
-
+
+
-
+
不可选择日期和时间
可用 DisabledDate 和 DisabledTime 分别禁止选择部分日期和时间,其中 DisabledTime 需要和 ShowTime 一起使用。
-
-
-
-
@@ -83,11 +83,11 @@
return new AntDatePickerDisabledTime(timeRange[4..15], timeRange[20..55], timeRange[3..19]);
}
}
-
+
定制日期单元格
使用 DateRender 可以自定义日期单元格的内容和样式。
-
+
@code{
@@ -96,22 +96,22 @@
if (currentViewDate.Day == 2)
{
return@二;
+ }
+ return @@(currentViewDate.Day);
+ };
}
-return @@(currentViewDate.Day);
-};
-}
-
+
额外的页脚
在浮层中加入额外的页脚,以满足某些定制信息的需求。
-
-
+
+
@code {
private RenderFragment extraFooter =@ExtraFooter;
}
-
+
三种大小
三种大小的输入框,若不设置,则为 Default。
@@ -121,21 +121,21 @@ return @@(currentViewDate.Day);
Small
-
+
@code {
private string datePickerSize = AntDatePickerSize.Default;
}
-
+
无边框
无边框样式。
-
-
-
-
-
+
+
+
+
+
@@ -144,7 +144,7 @@ return @@(currentViewDate.Day);
已实现DatePicker组件:支持date、decade、year、month、quarter、week模式
已实现:MonthPicker、RangePicker、WeekPicker、YearPicker、QuarterPicker(对应DatePicker的各种模式)
- 未实现的通用属性:AllowClear、GetPopupContainer、Locale、Mode(Mode为3.0妥协的功能,不打算支持)
+ 未实现的通用属性:AllowClear、Locale、Mode(Mode为3.0妥协的功能,不打算支持)
未实现的DatePicker属性:showTime.defaultValue、onOk