Skip to content

Commit f34c8f2

Browse files
committed
Add 'use-switch-checkbox' attribute to AbpInputTagHelper.
1 parent 5e7321e commit f34c8f2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ public class AbpInputTagHelper : AbpTagHelper<AbpInputTagHelper, AbpInputTagHelp
4747
public bool SuppressLabel { get; set; }
4848

4949
[HtmlAttributeName("floating-label")]
50-
5150
public bool FloatingLabel { get; set; }
5251

5352
public CheckBoxHiddenInputRenderMode? CheckBoxHiddenInputRenderMode { get; set; }
5453

54+
[HtmlAttributeName("use-switch-checkbox")]
55+
public bool UseSwitchCheckBox { get; set; } = false;
56+
5557
public bool AddMarginBottomClass { get; set; } = true;
5658

5759
public AbpInputTagHelper(AbpInputTagHelperService tagHelperService)

framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ out var suppress
6666
}
6767
if (isCheckBox)
6868
{
69-
output.Attributes.AddClass("custom-checkbox");
70-
output.Attributes.AddClass("custom-control");
69+
if (!TagHelper.UseSwitchCheckBox)
70+
{
71+
output.Attributes.AddClass("custom-checkbox");
72+
output.Attributes.AddClass("custom-control");
73+
}
74+
else
75+
{
76+
output.Attributes.AddClass("form-switch");
77+
}
78+
7179
output.Attributes.AddClass("form-check");
7280
}
7381
}
@@ -266,7 +274,7 @@ protected virtual bool IsInputCheckbox(TagHelperContext context, TagHelperOutput
266274
}
267275

268276
protected virtual async Task<string> GetLabelAsHtmlAsync(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag, bool isCheckbox)
269-
{
277+
{
270278
if (IsOutputHidden(inputTag) || TagHelper.SuppressLabel)
271279
{
272280
return string.Empty;
@@ -395,7 +403,7 @@ protected virtual async Task<string> GetLabelAsHtmlUsingTagHelperAsync(TagHelper
395403
}
396404
innerOutput.Content.AppendHtml($" <i class=\"{iconClass}\"></i>");
397405
}
398-
406+
399407
innerOutput.Content.AppendHtml(GetRequiredSymbol(context, output));
400408

401409
return innerOutput.Render(_encoder);

0 commit comments

Comments
 (0)