Skip to content
This repository was archived by the owner on Sep 18, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions DotnetViewComponents/ViewComponents/FieldsetViewComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace DotnetViewComponents.ViewComponents
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using DotnetViewComponents.ViewModels;

public class FieldsetViewComponent : ViewComponent
{
public IViewComponentResult Invoke(
string title,
List<FieldViewModel> fieldList)
{
var model = new FieldsetViewModel(title, fieldList);

return View(model);
}
}
}
29 changes: 29 additions & 0 deletions DotnetViewComponents/ViewModels/FieldsetViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Html;

namespace DotnetViewComponents.ViewModels
{
public class FieldsetViewModel
{
public FieldsetViewModel(
string title,
List<FieldViewModel> fieldList)
{
Title = title;
FieldList = fieldList;
}

public string Title { get; set; }
public List<FieldViewModel> FieldList { get; set; }

}

public class FieldViewModel
{
public FieldViewModel(Func<object, IHtmlContent> content)
{
Content = content;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misunderstanding this, @akdalin-hee, so bear with me. Is this expecting raw html to be passed in for each field in the fieldset? If so, it probably doesn't make much sense to include Fieldset as a component. Fieldsets are pretty thin on markup but have complex child components, so we might want to leave them out of the view component library?

}

public Func<object, IHtmlContent> Content { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@using DotnetViewComponents.ViewModels
@model FieldsetViewModel

<div class="nhsuk-tabs js-enabled" data-module="nhsuk-tabs">
<fieldset class="nhsuk-fieldset">
<legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--l">
<h1 class="nhsuk-fieldset__heading">
@Model.Title
</h1>
</legend>

@foreach (var field in Model.FieldList)
{
@field.Content(null)
}

</fieldset>
</div>