File tree Expand file tree Collapse file tree
demo/StaticSample/StaticSample/Components/Account/Pages
StaticInput.UnitTests.Viewer/Components/Tests/TextField
StaticInput.UnitTests/Components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4444 <MudStaticTextField @bind-Value =" @Input.Email" Adornment =" Adornment.End" AdornmentIcon =" @Icons.Material.Outlined.Email" autocomplete =" username"
4545 Class =" pb-2" Margin =" Margin.Dense" Variant =" Variant.Outlined" Label =" Email" For =" () => Input.Email" />
4646
47- <MudStaticTextField @bind-Value =" @Input.Password" Adornment = " Adornment.End " AdornmentIcon = " @Icons.Material. Outlined.VisibilityOff " AdornmentClickFunction = " showPassword "
48- autocomplete = " current-password " Class = " pb-2 " Margin = " Margin.Dense " Variant = " Variant. Outlined" Label = " Password "
49- InputType =" InputType.Password" For =" () => Input.Password" />
47+ <MudStaticTextField @bind-Value =" @Input.Password" autocomplete = " current-password " Class = " pb-2 " Margin = " Margin.Dense " Variant = " Variant. Outlined" Label = " Password "
48+ Adornment = " Adornment.End " AdornmentIcon = " @Icons.Material. Outlined.Visibility " AdornmentToggledIcon = " @Icons.Material.Outlined.VisibilityOff "
49+ AdornmentClickFunction = " showPassword " InputType =" InputType.Password" For =" () => Input.Password" />
5050
5151 <MudStack Row =" true" AlignItems =" AlignItems.Center" Justify =" Justify.SpaceBetween" >
5252 <MudStaticSwitch @bind-Value =" Input.RememberMe" Color =" Color.Primary" Label =" Remember Me" Typo =" Typo.body2" />
Original file line number Diff line number Diff line change 5252 /// </example >
5353 /// </remarks >
5454 [Parameter ] public string ? AdornmentClickFunction { get ; set ; }
55+ [Parameter ] public string ? AdornmentToggledIcon { get ; set ; }
5556 [Parameter ] public Expression <Func <string >> ? ValueExpression { get ; set ; }
5657
5758 private string _name = string .Empty ;
142143 {
143144 const inputControl = inputElement .closest (" .mud-input-control" );
144145 const buttonElement = inputControl .querySelector (' button' );
146+ const svgElement = buttonElement .querySelector (" svg" );
147+ const icon = ' @AdornmentIcon' ;
148+ const toggleIcon = ' @AdornmentToggledIcon' ;
149+
150+ let isToggled = false ;
145151
146152 if (buttonElement) {
147153 buttonElement .addEventListener (' click' , function (event ) {
154+
155+ if (svgElement && toggleIcon)
156+ {
157+ isToggled = ! isToggled;
158+ svgElement .innerHTML = isToggled ? toggleIcon : icon;
159+ }
160+
148161 if (typeof window [onAdornmentClick] === ' function' ) {
149162 window [onAdornmentClick](inputElement, event .target );
150163 }
Original file line number Diff line number Diff line change 99 Adornment =" Adornment.End" AdornmentIcon =" @Icons.Material.Outlined.Email"
1010 Class =" pb-2" Margin =" Margin.Dense" Variant =" Variant.Outlined" />
1111 <MudStaticTextField @bind-Value =" @Model.Password" For =" () => Model.Password" Label =" Password" Placeholder =" Password"
12- Adornment =" Adornment.End" AdornmentIcon =" @Icons.Material.Outlined.VisibilityOff"
12+ Adornment =" Adornment.End" AdornmentIcon =" @Icons.Material.Outlined.Visibility"
13+ AdornmentToggledIcon =" @Icons.Material.Outlined.VisibilityOff"
1314 AdornmentClickFunction =" handleAdornmentClick" InputType =" InputType.Password"
1415 Class =" pb-2" Margin =" Margin.Dense" Variant =" Variant.Outlined" />
1516</EditForm >
Original file line number Diff line number Diff line change @@ -226,5 +226,25 @@ public async Task TextField_AdornmentButton_IsClickable()
226226
227227 message . Should ( ) . Be ( "Adornment clicked!" ) ;
228228 }
229+
230+ [ Fact ]
231+ public async Task TextField_AdornmentButton_CanToggle ( )
232+ {
233+ var url = typeof ( TextFieldAdornmentTest ) . ToQueryString ( ) ;
234+
235+ await Page . GotoAsync ( url ) ;
236+
237+ var button = await Page . QuerySelectorAsync ( "input[type=\" password\" ] ~ .mud-input-adornment .mud-icon-button" ) ;
238+ var innerHtml = await button ! . InnerHTMLAsync ( ) ;
239+
240+ innerHtml . Should ( ) . Contain ( "<path d=\" M0 0h24v24H0V0z\" fill=\" none\" ></path>" ) ;
241+
242+ await button . ClickAsync ( ) ;
243+
244+ button = await Page . QuerySelectorAsync ( "input[type=\" password\" ] ~ .mud-input-adornment .mud-icon-button" ) ;
245+ innerHtml = await button ! . InnerHTMLAsync ( ) ;
246+
247+ innerHtml . Should ( ) . Contain ( "<path d=\" M0 0h24v24H0V0zm0 0h24v24H0V0zm0 0h24v24H0V0zm0 0h24v24H0V0z\" fill=\" none\" ></path>" ) ;
248+ }
229249 }
230250}
You can’t perform that action at this time.
0 commit comments