ant-design-blazor/components/select/internal/SelectContent.razor.cs
Andrzej Bakun 152a574577 feat(module: overlay): OverlayTrigger not bound to a div (#937)
* feat(module:overlay): OverlayTrigger not bound to a div

* feat(module:overlay): OverlayTrigger not bound to a div

* feat(module:overlay): Logic transfer to single Overlay

* feat(module:overlay): remove obsolete duplication

* feat(module:Tooltip): Add for unbounded oncontextmenu event handler

* feat(module:tooltip): unbound js event listeners remove

* docs(module:tooltip): unbound explanation

* fix(module:button): attach Ref to top level html element @ref

* feat(module:dropdown&tooltip&popconfirm&popover): Overlay not bound to a div

* docs(module:dropdown&tooltip&popconfirm&popover): unbound explanation

* feat(module:OverlayTrigger): common logic relocation

* feat(module:overlaytrigger): Overlay not bound to a div

* feat(module:DatePicker): Overlay not bound to a div

* feat(module:select): Overlay not boud to div

* fix(module:select): onclickarrow event relocation

* fix(module:select): rename Show to OnArrowClick

* feat(module:avatar): Overlay not bound to a div

* docs(module:avatar): demo switch to unbound version

* feat(module:autocomplete): partial OverlayTrigger not bound to a div

* feat(module:slider): tooltip

* docs(module:slider): tooltip

* fix(module:overlay): add SetVisible method

* feat: set Ref where missing, performance

components register Ref when missing
IsFixed flag for CascadeValue changed
hard-code sequence numbers when using RenderTreeBuilder
Rate component use Tooltip Unbound version
Tabs test fix

* fix: revert changes (accidental)

* feat(module:upload): tooltip with unbound usage

* feat(module:table): column use of unbound tooltip

* feat(module:autocomplete):overlay unbound from div

* fix(module:upload): missing div restore

Co-authored-by: James Yeung <shunjiey@hotmail.com>
2021-01-21 17:20:10 +08:00

121 lines
4.0 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
#pragma warning disable 1591 // Disable missing XML comment
namespace AntDesign.Select.Internal
{
public partial class SelectContent<TItemValue, TItem>
{
[CascadingParameter(Name = "ParentSelect")] internal Select<TItemValue, TItem> ParentSelect { get; set; }
[CascadingParameter(Name = "ParentLabelTemplate")] internal RenderFragment<TItem> ParentLabelTemplate { get; set; }
[CascadingParameter(Name = "ShowSearchIcon")] internal bool ShowSearchIcon { get; set; }
[CascadingParameter(Name = "ShowArrowIcon")] internal bool ShowArrowIcon { get; set; }
[Parameter] public string Prefix { get; set; }
[Parameter] public string Placeholder { get; set; }
[Parameter] public bool IsOverlayShow { get; set; }
[Parameter] public bool ShowPlaceholder { get; set; }
[Parameter] public EventCallback<ChangeEventArgs> OnInput { get; set; }
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyUp { get; set; }
[Parameter] public EventCallback<KeyboardEventArgs> OnKeyDown { get; set; }
[Parameter] public EventCallback<FocusEventArgs> OnFocus { get; set; }
[Parameter] public EventCallback<FocusEventArgs> OnBlur { get; set; }
[Parameter] public EventCallback<MouseEventArgs> OnClearClick { get; set; }
[Parameter] public EventCallback<SelectOptionItem<TItemValue, TItem>> OnRemoveSelected { get; set; }
[Parameter] public string SearchValue { get; set; }
[Parameter] public ForwardRef RefBack { get; set; } = new ForwardRef();
protected ElementReference Ref
{
get { return _ref; }
set
{
_ref = value;
RefBack?.Set(value);
}
}
private string _inputStyle = string.Empty;
private string _inputWidth;
private bool _suppressInput;
private ElementReference _ref;
protected override void OnInitialized()
{
SetSuppressInput();
}
protected override Task OnAfterRenderAsync(bool firstRender)
{
SetSuppressInput();
return base.OnAfterRenderAsync(firstRender);
}
protected override Task OnParametersSetAsync()
{
if (ParentSelect.SelectMode != SelectMode.Default) // ToDo Fix class
SetInputWidth();
return base.OnParametersSetAsync();
}
private void SetInputWidth()
{
if (!string.IsNullOrWhiteSpace(SearchValue))
{
_inputWidth = $"width: {4 + SearchValue.Length * 8}px;";
}
else
{
if (ParentSelect.HasValue)
{
_inputWidth = "width: 4px;"; //ToDo fix class
}
else
{
_inputWidth = "width: 4px; margin-left: 6.5px;"; //ToDo fix class
}
}
}
private void SetSuppressInput()
{
if (!ParentSelect.IsSearchEnabled)
{
if (!_suppressInput)
{
_suppressInput = true;
_inputStyle = "caret-color: transparent;";
}
}
else
{
if (_suppressInput)
{
_suppressInput = false;
_inputStyle = string.Empty;
}
}
}
protected void OnKeyPressEventHandler(KeyboardEventArgs _)
{
if (!ParentSelect.IsSearchEnabled)
SearchValue = string.Empty;
}
private Dictionary<string, object> AdditonalAttributes()
{
var dict = new Dictionary<string, object>();
if (ParentSelect.Disabled)
dict.Add("tabindex", "-1");
return dict;
}
}
}