Skip to content

Commit

Permalink
revert Improved display for Floating Labels
Browse files Browse the repository at this point in the history
  • Loading branch information
masoodkhoshgard committed Jul 20, 2023
1 parent 1332be6 commit 8b6a375
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,10 @@ protected virtual void AddPlaceholderAttribute(TagHelperOutput inputTagHelperOut

var attribute = TagHelper.AspFor.ModelExplorer.GetAttribute<Placeholder>();

if (attribute != null || TagHelper.FloatingLabel)
if (attribute != null)
{
var placeholderLocalized = _tagHelperLocalizer.GetLocalizedText(attribute?.Value ?? string.Empty, TagHelper.AspFor.ModelExplorer);
if (string.IsNullOrWhiteSpace(placeholderLocalized))
placeholderLocalized = TagHelper.AspFor.Name;
var placeholderLocalized = _tagHelperLocalizer.GetLocalizedText(attribute.Value, TagHelper.AspFor.ModelExplorer);

inputTagHelperOutput.Attributes.Add("placeholder", placeholderLocalized);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Diagnostics;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Localization;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers;
using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions;
using Volo.Abp.Localization;
Expand Down Expand Up @@ -37,7 +38,7 @@ public AbpSelectTagHelperService(
_abpEnumLocalizer = abpEnumLocalizer;
}

public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await output.GetChildContentAsync();

Expand Down Expand Up @@ -73,8 +74,7 @@ protected virtual async Task<string> GetFormInputGroupAsHtmlAsync(TagHelperConte
var validation = await GetValidationAsHtmlAsync(context, output, selectTag);
var infoText = GetInfoAsHtml(context, output, selectTag);

return TagHelper.FloatingLabel ? selectAsHtml + Environment.NewLine + label + Environment.NewLine + infoText + Environment.NewLine + validation :
label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText + Environment.NewLine + validation;
return label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText + Environment.NewLine + validation;
}

protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml)
Expand Down Expand Up @@ -156,15 +156,23 @@ protected virtual List<SelectListItem> GetSelectItems(TagHelperContext context,
}

var selectItemsAttribute = TagHelper.AspFor.ModelExplorer.GetAttribute<SelectItems>();
return selectItemsAttribute != null
? GetSelectItemsFromAttribute(selectItemsAttribute, TagHelper.AspFor.ModelExplorer)
: throw new Exception("No items provided for select attribute.");
if (selectItemsAttribute != null)
{
return GetSelectItemsFromAttribute(selectItemsAttribute, TagHelper.AspFor.ModelExplorer);
}

throw new Exception("No items provided for select attribute.");
}

private bool IsEnum()
{
var value = TagHelper.AspFor.Model;
return (value != null && value.GetType().IsEnum) || TagHelper.AspFor.ModelExplorer.Metadata.IsEnum;
if (value != null && value.GetType().IsEnum)
{
return true;
}

return TagHelper.AspFor.ModelExplorer.Metadata.IsEnum;
}

protected virtual async Task<string> GetLabelAsHtmlAsync(TagHelperContext context, TagHelperOutput output, TagHelperOutput selectTag)
Expand Down Expand Up @@ -288,7 +296,12 @@ protected virtual List<SelectListItem> GetSelectItemsFromAttribute(
{
var selectItems = selectItemsAttribute.GetItems(explorer)?.ToList();

return selectItems ?? new List<SelectListItem>();
if (selectItems == null)
{
return new List<SelectListItem>();
}

return selectItems;
}

protected virtual async Task<string> GetLabelAsHtmlUsingTagHelperAsync(TagHelperContext context, TagHelperOutput output)
Expand Down Expand Up @@ -324,13 +337,17 @@ protected virtual string GetSize(TagHelperContext context, TagHelperOutput outpu
TagHelper.Size = attribute.Size;
}

return TagHelper.Size switch
switch (TagHelper.Size)
{
AbpFormControlSize.Small => "form-select-sm",
AbpFormControlSize.Medium => "form-select-md",
AbpFormControlSize.Large => "form-select-lg",
_ => "",
};
case AbpFormControlSize.Small:
return "form-select-sm";
case AbpFormControlSize.Medium:
return "form-select-md";
case AbpFormControlSize.Large:
return "form-select-lg";
}

return "";
}

protected virtual TagHelperAttributeList GetInputAttributes(TagHelperContext context, TagHelperOutput output)
Expand Down Expand Up @@ -359,7 +376,7 @@ protected virtual void LeaveOnlyGroupAttributes(TagHelperContext context, TagHel

foreach (var tagHelperAttribute in tagHelperAttributes)
{
var nameWithoutPrefix = tagHelperAttribute.Name[groupPrefix.Length..];
var nameWithoutPrefix = tagHelperAttribute.Name.Substring(groupPrefix.Length);
var newAttritube = new TagHelperAttribute(nameWithoutPrefix, tagHelperAttribute.Value);
output.Attributes.Add(newAttritube);
}
Expand Down

0 comments on commit 8b6a375

Please sign in to comment.