Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

vernou
Copy link
Member

@vernou vernou commented Nov 25, 2024

Description

Fixes #10252

When MudTextField has a mask of type PatternMask, set the parameter MudTextField.Value update the input text. But if the mask is of another type, then the input text isn't updated.

The reason is the default mask in MudMask is a PatternMask :

public partial class MudMask : MudBaseInput<string>
{
    ...
    private IMask _mask = new PatternMask("** **-** **");

So when MudTextField set the mask of type PatternMask to MudMask, they don't share the same instance :

public partial class MudMask : MudBaseInput<string>
{
    private void SetMask(IMask? other)
    {
        if (_mask.GetType() == other.GetType())
        {
            // When type is the same, don't share the same instance
            _mask.UpdateFrom(other);
            return;
        }
        // When type is different, share the same instance
        _mask = other;
    }

And it's work fine. But when MudTextField set the mask of another type PatternMask to MudMask, they share the same instance.

MudMask update the inner text when MudMask.Mask.Text is different to MudTextField.Mask.Text. But like MudMask.Mask and MudTextField.Mask is the same instance, the condition is always false.

To fix the problem, I modified the condition to verrify if the MudMask inner text is different from MudTextField.Mask.Text.

How Has This Been Tested?

I added tests for each IMask implementation.

Type of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (fix or improvement to the website or code docs)

Checklist

  • The PR is submitted to the correct branch (dev).
  • My code follows the code style of this project.
  • I've added relevant tests.

@github-actions github-actions bot added the bug Unexpected behavior or functionality not working as intended label Nov 25, 2024
Copy link

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.43%. Comparing base (7625925) to head (1540562).
Report is 21 commits behind head on dev.

Additional details and impacted files
@@           Coverage Diff           @@
##              dev   #10328   +/-   ##
=======================================
  Coverage   91.42%   91.43%           
=======================================
  Files         415      415           
  Lines       13039    13039           
  Branches     2475     2475           
=======================================
+ Hits        11921    11922    +1     
  Misses        551      551           
+ Partials      567      566    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vernou vernou marked this pull request as ready for review November 26, 2024 12:25
@vernou vernou requested a review from ScarletKuro November 28, 2024 00:00
@vernou vernou self-assigned this Nov 28, 2024
@ScarletKuro ScarletKuro requested a review from henon November 29, 2024 17:05
Copy link
Member

@ScarletKuro ScarletKuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself looks good to me. Not an expert in masking, never used it to be fair.
@henon ?

Copy link
Collaborator

@henon henon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vernou good fix.

@henon henon changed the title MudTextField : With mask, set parameter value updates the input text MudTextField: With mask, setting parameter value updates the input text Dec 6, 2024
@henon henon merged commit 50d93b9 into MudBlazor:dev Dec 6, 2024
5 checks passed
@vernou vernou deleted the 10252-textfield-mask-update branch December 6, 2024 11:10
LLauter pushed a commit to cannellamedia/MudBlazor that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected behavior or functionality not working as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MudTextField is not updated on value change when RegexMask is set
3 participants