Skip to content

The Clear button in MudInputExtended and its children does not disappear if the component is ReadOnly #617

Description

@cherepakhina

Note: I have tried out MudSelectExtended, MudTextFieldExtended, MudComboBox and the base MudInputExtended.

If the field is empty and the ReadOnly is set to true, the Clear button doesn't show up so everything is normal. If it isn't empty, the Clear button stays and clicking it clears the bound value despite the field being ReadOnly. I suspect that it could have something to do with the ReadOnly being hardcoded to true in ShowClearButton of MudInputExtended.razor.cs.

Here's the reproduction code with the ReadOnly being set as a parameter in the components directly or cascaded from MudForm:

 <MudCard>
<MudCardHeader>
Just a selector
</MudCardHeader>
<MudCardContent>
<MudSelectExtended @bind-Value="_value" ItemCollection="_valueList" Clearable ReadOnly="_readOnly" Label="Value selector" />
<MudComboBox @bind-Value="_value" Clearable ReadOnly="_readOnly" Label="Combo box selector">
@foreach (var item in _valueList)
{
<MudComboBoxItem Value="@item" Text="@item"></MudComboBoxItem>
}
</MudComboBox>
<MudInputExtended @bind-Value="_value" Clearable ReadOnly="_readOnly" Label="Value input" />
<MudTextFieldExtended @bind-Value="_value" Clearable ReadOnly="_readOnly" Label="Value input (text)" />
</MudCardContent>
</MudCard>
<MudCard>
<MudCardHeader>
Selector inside a MudForm
</MudCardHeader>
<MudCardContent>
<MudForm ReadOnly="_readOnly">
<MudSelectExtended @bind-Value="_value" ItemCollection="_valueList" Clearable Label="Value selector" />
<MudComboBox @bind-Value="_value" Clearable ReadOnly="_readOnly" Label="Combo box selector">
@foreach (var item in _valueList)
{
<MudComboBoxItem Value="@item" Text="@item"></MudComboBoxItem>
}
</MudComboBox>
<MudInputExtended @bind-Value="_value" Clearable Label="Value input" />
<MudTextFieldExtended @bind-Value="_value" Clearable Label="Value input" />
</MudForm>
</MudCardContent>
</MudCard>
<MudSwitch @bind-Value="_readOnly" Label="ReadOnly" />
@code {
string? _value;
bool _readOnly = false;
List<string?> _valueList = ["lorem", "ipsum", "dolor"];
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions