I need to be able to allow our users to tab into the dropdownlist control and open it with enter (similar to standard HTML select).
Here is also a sample from the W3 documentation to compare against: DropDownList keyboard support.
Before, the Value from the first item in the Data was populated through @bind-Value to the view model. It no longer is.
In the following snippet, I expect to see "1" in the initial load of the page, but I see "0" - the default value for the integer.
@selectedValue
<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="@selectedValue">
</TelerikDropDownList>
@code {
//in a real case, the model is usually in a separate file
//the model type and value field type must be provided to the dropdpownlist
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
int selectedValue { get; set; }
}
Currently, a TextField value of empty string will produce a blank item in the dropdown.
On the other hand, a null TextField value will produce the fully qualified class name.
Here are possible workarounds: https://blazorrepl.telerik.com/myOlFpFb1465jW8E07
TlerikDropDownList keyboard navigation works differently from native html select.
In case we have a list with many similar options, for example:
011
021
211
....
In this case with native html select I can type 02 to select 021, but with TlerikDropDownList this would select 211.
If you type swiftly multiple printable characters, the DropDownList keyboard navigation will react only to the first character.
Here is the scenario:
In this case, reducing or increasing the number of visible dropdown items does not adjust the open dropdown's position. As a result, it may either float too high, or overflow the screen.
Possible workarounds are:
Here is a test page:
<div style="height:80vh;background:linear-gradient(white,orange)">
<ol>
<li>Open a ComboBox</li>
<li>Type a character to filter and reduce the visible data items</li>
<li>Observe incorrect popup position that leaves a gap</li>
</ol>
<ol>
<li>Focus a closed ComboBox</li>
<li>Type a character to filter and display a reduced list of data items</li>
<li>Remove the filter string to increase the visible data item count</li>
<li>Observe incorrect popup position that overflows the screen</li>
</ol>
</div>
WORKS:
<TelerikComboBox Data="@ListItems"
@bind-Value="@SelectedValue"
TextField="@nameof(ListItem.Text)"
ValueField="@nameof(ListItem.Id)"
Filterable="true"
FilterOperator="@StringFilterOperator.Contains"
Width="300px" />
BROKEN:
<TelerikComboBox Data="@ListItems"
@bind-Value="@SelectedValue"
TextField="@nameof(ListItem.Text)"
ValueField="@nameof(ListItem.Id)"
Filterable="true"
FilterOperator="@StringFilterOperator.Contains"
Width="300px">
<ComboBoxSettings>
<ComboBoxPopupSettings Height="auto" MinHeight="50px" MaxHeight="60vh" />
</ComboBoxSettings>
</TelerikComboBox>
<div style="height:80vh;background:linear-gradient(orange, white)">
</div>
@code {
private List<ListItem> ListItems { get; set; } = new();
private int SelectedValue { get; set; }
protected override void OnInitialized()
{
ListItems = new List<ListItem>();
for (int i = 1; i <= 50; i++)
{
ListItems.Add(new ListItem()
{
Id = i,
Text = $"Item {i} {(char)Random.Shared.Next(65, 91)}{(char)Random.Shared.Next(65, 91)}{(char)Random.Shared.Next(65, 91)}{(char)Random.Shared.Next(65, 91)}"
});
}
base.OnInitialized();
}
public class ListItem
{
public int Id { get; set; }
public string Text { get; set; } = string.Empty;
}
}
When the Value you bind to the DropDownList is null (for example, because it is a model that is not filled in by the user yet, and you need to perform validation), the component throws a null reference exception.
This does not happen for a nullable integer (example here)
Reproducible:
@
using
System.ComponentModel.DataAnnotations
@
using
Telerik.Blazor.Components.DropDownList
<EditForm Model=
"@PageData"
OnValidSubmit=
"@HandleValidSubmit"
>
<DataAnnotationsValidator />
<ValidationSummary />
@PageData.QuoteState
<TelerikDropDownList bind-Value=
"@PageData.QuoteState"
DefaultItem=
"@Hint"
Width=
"300px"
Data=
"@states"
TextField=
"stateName"
ValueField=
"stateID"
>
</TelerikDropDownList>
<ValidationMessage For=
"@(() => PageData.QuoteState)"
></ValidationMessage>
<button type=
"submit"
>Submit</button>
</EditForm>
@functions {
public
MyViewModel PageData {
get
;
set
; } =
new
MyViewModel();
public
statesModel Hint {
get
;
set
; } =
new
statesModel { stateID =
null
, stateName =
"Not Selected"
};
public
class
statesModel
{
public
string
stateID {
get
;
set
; }
public
string
stateName {
get
;
set
; }
}
public
class
MyViewModel
{
[Required(ErrorMessage =
"State is mandatory."
)]
//the value field in the dropdown model must be null in the default item
public
string
QuoteState {
get
;
set
; }
}
public
IEnumerable<statesModel> states =
new
List<statesModel>
{
new
statesModel { stateID =
"ACT"
, stateName =
"ACT"
},
new
statesModel { stateID =
"NSW"
, stateName =
"NSW"
},
new
statesModel { stateID =
"NT"
, stateName =
"NT"
},
new
statesModel { stateID =
"QLD"
, stateName =
"QLD"
},
new
statesModel { stateID =
"SA"
, stateName =
"SA"
},
new
statesModel { stateID =
"TAS"
, stateName =
"TAS"
},
new
statesModel { stateID =
"VIC"
, stateName =
"VIC"
},
new
statesModel { stateID =
"WA"
, stateName =
"WA"
}
};
void
HandleValidSubmit()
{
Console.WriteLine(
"OnValidSubmit"
);
}
}
As stated in the documentation the Event OnChange for DropDownList is shown by intellisense but should not be used. However, in some situations it would be very useful to bind the value of the DropDownList and additionally have an event when the value changes, e.g. show additional inputs when a value is selected.
Currently it is either possible to have data binding to value by @bind-Value or listen for the changed event by using Value and ValueChanged.
Clicking on the <label> opens the dropdown, but clicking on its main element does not
Selected value: @selectedValue
<br />
<label>some label for the dropdown, open it and test whether clicking outside closes it
<TelerikDropDownList Data="@myDdlData" TextField="MyTextField" ValueField="MyValueField" @bind-Value="selectedValue">
</TelerikDropDownList>
</label>
@code {
//in a real case, the model is usually in a separate file
//the model type and value field type must be provided to the dropdpownlist
public class MyDdlModel
{
public int MyValueField { get; set; }
public string MyTextField { get; set; }
}
IEnumerable<MyDdlModel> myDdlData = Enumerable.Range(1, 20).Select(x => new MyDdlModel { MyTextField = "item " + x, MyValueField = x });
int selectedValue { get; set; } = 3; //usually the current value should come from the model data
}