Skip to content

Commit

Permalink
Don't render empty aria-describedby attributes (#247)
Browse files Browse the repository at this point in the history
Fixes #246
  • Loading branch information
gunndabad authored Mar 14, 2023
1 parent b2ffbd2 commit 787a5e2
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void AddItem(CheckboxesItem item)
AppendToDescribedBy(ref itemDescribedBy, hintId);
}

if (itemDescribedBy != null)
if (!string.IsNullOrEmpty(itemDescribedBy))
{
input.Attributes.Add("aria-describedby", itemDescribedBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public TagBuilder GenerateFieldset(
tagBuilder.MergeOptionalAttributes(attributes);
tagBuilder.MergeCssClass("govuk-fieldset");

if (role != null)
if (!string.IsNullOrEmpty(role))
{
tagBuilder.Attributes.Add("role", role);
}

if (describedBy != null)
if (!string.IsNullOrEmpty(describedBy))
{
tagBuilder.Attributes.Add("aria-describedby", describedBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public TagBuilder GenerateFileUpload(
tagBuilder.Attributes.Add("name", name);
tagBuilder.Attributes.Add("type", "file");

if (describedBy != null)
if (!string.IsNullOrEmpty(describedBy))
{
tagBuilder.Attributes.Add("aria-describedby", describedBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TagBuilder GenerateInsetText(
tagBuilder.MergeOptionalAttributes(attributes);
tagBuilder.MergeCssClass("govuk-inset-text");

if (id != null)
if (!string.IsNullOrEmpty(id))
{
tagBuilder.Attributes.Add("id", id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public TagBuilder GenerateSelect(
tagBuilder.Attributes.Add("id", id);
tagBuilder.Attributes.Add("name", name);

if (describedBy != null)
if (!string.IsNullOrEmpty(describedBy))
{
tagBuilder.Attributes.Add("aria-describedby", describedBy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public virtual TagBuilder GenerateTextArea(
tagBuilder.Attributes.Add("name", name);
tagBuilder.Attributes.Add("rows", rows.ToString());

if (describedBy != null)
if (!string.IsNullOrEmpty(describedBy))
{
tagBuilder.Attributes.Add("aria-describedby", describedBy);
}

if (autocomplete != null)
if (!string.IsNullOrEmpty(autocomplete))
{
tagBuilder.Attributes.Add("autocomplete", autocomplete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public TagBuilder GenerateTextInput(
tagBuilder.Attributes.Add("value", value);
}

if (describedBy != null)
if (!string.IsNullOrEmpty(describedBy))
{
tagBuilder.Attributes.Add("aria-describedby", describedBy);
}

if (autocomplete != null)
if (!string.IsNullOrEmpty(autocomplete))
{
tagBuilder.Attributes.Add("autocomplete", autocomplete);
}
Expand All @@ -67,7 +67,7 @@ public TagBuilder GenerateTextInput(
tagBuilder.Attributes.Add("pattern", pattern);
}

if (inputMode != null)
if (!string.IsNullOrEmpty(inputMode))
{
tagBuilder.Attributes.Add("inputmode", inputMode);
}
Expand Down

0 comments on commit 787a5e2

Please sign in to comment.