MudTextField with Mask enabled has unexpected behavior on mobile browsers
See original GitHub issueBug type
Component
Component name
MudMask MudTextField
What happened?
When we set up a MudTextField with a Mask, everything works fine on desktop browsers. If we go to a real mobile browser, it will not get the updated value as we fill. An example is this simple code :
<MudTextField T="string" Label="CEP" Variant="Variant.Outlined" HelperTextOnFocus="true" HelperText="Rua do titular da conta"
InputType="InputType.Text" Mask="@(new PatternMask("00.000-000"))"
Required="true" RequiredError="CEP é obrigatório">
</MudTextField>
This makes the Required property not work correctly. This also impacts Validator behaviour. This is probably connected to events being handled.
Expected behavior
Expected behaviour is when using mask, even on mobile browsers at least the correct value is passed ahead for validators and MudBlazor actions. Ideal behaviour is Mask being applied at least when focus is out or value is detected as changed, since using ValueChanged works pretty OK.
Reproduction link
https://try.mudblazor.com/snippet/QuQmOymJeZQhVpOu
Reproduction steps
- Create a MudTextField
- Add PatternMask
- Enable any validation, like Required or Validation func.
- Open on real mobile browser
- Fill the MudTextField
Relevant log output
No response
Version (bug)
6.0.10
Version (working)
No response
What browsers are you seeing the problem on?
Chrome, Microsoft Edge
On what operating system are you experiencing the issue?
Android
Pull Request
- I would like to do a Pull Request
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created a year ago
- Reactions:5
- Comments:29 (8 by maintainers)
Top Related StackOverflow Question
I also found this problem while playing with the demo on mobile (Chrome on Android). After some debugging on my mobile browser I found that the event provided to this method differs from what I see when debugging on Chrome desktop . For example, on this demo, if I press the letter
The logic in the KeyInterceptor depends on the value provided by the
Aon mobile theargs.keyproperty value isUnidentified, whereas on desktop its value isA. ThekeyCodeis also off…keyproperty of the event for it to work properly.Additionally, on Chrome mobile the pressed key goes straight into the input before the
I found this and this, which makes me think that the current approach taken by the key interceptor in MudBlazor is not suitable for mobile.
keydownevent gets fire.I’m going to dig more into this to confirm my findings. If I got something of the above wrong please let me know.
If I can find a solution I’ll submit a PR with it.
CC @Mr-Technician @mckaragoz
Looking at this issue: https://bugs.chromium.org/p/chromium/issues/detail?id=118639, the GBoard don’t send the
keycodein thekeydownevent (except for special ones like “Delete”,“Backspace”). As can be seen in the above link, the GBoard Team consider it as a choice, not a bug. So the current Mud implementation should not rely on thekeydownevent to work properly on Android.I think most js libs that works everywhere, like
IMaskJS,ng-maskandv-mask, uses theinputevent. In this event, they sychronously check the new input value, compute the masked text, set it in the input value and adjust the cursor position.It is important to be synchonous, otherwise will occur some underised flickering effects. Also, in my experiments, after an asynchonous call inside the
inputevent handler theinput.setSelectionRangecalls won’t work. This means that the implementation will have to usedotnetRef.invokeMethodinstead ofdotnetRef.invokeMethodAsyncwhen computing the mask.I’m currently using a workaround (WASM only) for this problem, with some custom script and Reflection.
Add the following script in the index.html:
Create a component that inherits from
MudTextField, ex:AppTextField.razor:Then use your custom inherited component instead of MudTextField:
In my app I had to adapt the
MudDatePickertoo.AppDatePicker.razor: