Comments (1)
Looks like all MatSelectItem, MatSelectValue and MatSelect have the same issue. The main problem is that the value of selected item text is updated using JavaScript and not using C#. As a result one of the ways to fix it is to manually call JavaScript. Not ideal but solves the problem.
Below are two possible solutions I came up with (version 2.10.0):
- Extension method for manual update of selected text:
public static class MatSelectItemExtensions
{
public static void UpdateSelectedText<T>(this MatSelectItem<T> select)
{
Type selectType = typeof(MatSelectItem<T>);
Type itemType = typeof(T);
// Get currently selected item
PropertyInfo currentValueProperty = selectType.GetProperty("CurrentValue", BindingFlags.NonPublic | BindingFlags.Instance);
T currentValue = (T)currentValueProperty.GetValue(select);
// Call OnValueChanged which accepts old value and new value. Old value does not seem to be used so we can just provide null
MethodInfo onValueChangedMethod = selectType.GetMethod("OnValueChanged", BindingFlags.NonPublic | BindingFlags.Instance, new Type[] { itemType, itemType });
onValueChangedMethod.Invoke(select, new object[] { null, currentValue });
}
}
- Custom class derived from MatSelectItem with extra method for manual update of selected text:
public class MatSelectItemFixed<T> : MatSelectItem<T>
{
internal MatBlazorSwitchT<int> switchTK = MatBlazorSwitchT<int>.Get();
public void UpdateSelectedText()
{
CallAfterRender(async () =>
{
await JsInvokeAsync<object>("matBlazor.matSelect.setValue", Ref, switchTK.FormatValueAsString(GetKeyFromValue(CurrentValue), null));
});
}
}
For version 2.8.0 the solution is more or less the same:
public static class MatSelectItemExtensions
{
public static void UpdateSelectedText<T>(this MatSelectItem<T> select)
{
// Call OnValueChanged which accepts bool value that indicates whether value is changed
Type selectType = typeof(MatSelectItem<T>);
MethodInfo onValueChangedMethod = selectType.GetMethod("OnValueChanged", BindingFlags.NonPublic | BindingFlags.Instance);
onValueChangedMethod.Invoke(select, new object[] { true });
}
}
from matblazor.
Related Issues (20)
- Treeview - not rendering correctly HOT 5
- MatSelectItem - affecting the surrounding environment
- IMatDialogService + BUnit HOT 14
- Elements of the MatPortalHost are not themed by a MatThemeProvider
- MatFileUpload (Missing "Attach_file" icon)
- Enable Dark Theme - Documentations? HOT 3
- ProgressCircle renders incorrectly
- MatBlazor DatePicker disabled doesn't disable the calendar button
- Deleting Element in MatList doesnt delete MatMenu reference
- SelectValue When Scrolling while expanded dropdown doesn't stay at input HOT 1
- TreeView: Performance/rendering improvement for big trees with many nodes
- MudTable does not render correctly when using iPhone SE
- MatTextfield - autocomplete off not working while Type is password
- MatAutocompleteList - CustomStringSelector not working with default value (possible bug)
- HowTo Translate the datepicker ? HOT 1
- Floating label by default
- how to call function after toast hide
- MatPaginator -> [Parameter] PageIndex
- MatSelect options dont show when loaded as disabled then changed dynamically to not be disabled
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matblazor.