diff --git a/app/components/open_project/common/attribute_label_component.html.erb b/app/components/open_project/common/attribute_label_component.html.erb index c4d4bf4fd6a..3f6ec4c6061 100644 --- a/app/components/open_project/common/attribute_label_component.html.erb +++ b/app/components/open_project/common/attribute_label_component.html.erb @@ -1,4 +1,7 @@ <%= render Primer::ConditionalWrapper.new(condition: !@tag.nil?, trim: true, **@system_arguments) do %> <%= content %> + <% if @required %> + <%= render Primer::BaseComponent.new(tag: :span, ml: 1, aria: { hidden: true }).with_content("*") %> + <% end %> <%= render OpenProject::Common::AttributeHelpTextComponent.new(help_text: @help_text) if @help_text.present? %> <% end %> diff --git a/app/components/open_project/common/attribute_label_component.rb b/app/components/open_project/common/attribute_label_component.rb index d56673f5a59..bc019c7dd3b 100644 --- a/app/components/open_project/common/attribute_label_component.rb +++ b/app/components/open_project/common/attribute_label_component.rb @@ -36,6 +36,7 @@ module OpenProject model:, tag: :span, current_user: User.current, + required: false, **system_arguments ) super() @@ -48,6 +49,8 @@ module OpenProject "op-attribute-label" ) + @required = required + @help_text = ::AttributeHelpText.for(model) &.cached(current_user) &.[](AttributeHelpText.normalize_value_for(:attribute_name, attribute)) diff --git a/modules/overviews/app/components/overviews/project_custom_fields/item_component.html.erb b/modules/overviews/app/components/overviews/project_custom_fields/item_component.html.erb index e3b102153d0..fe705d10767 100644 --- a/modules/overviews/app/components/overviews/project_custom_fields/item_component.html.erb +++ b/modules/overviews/app/components/overviews/project_custom_fields/item_component.html.erb @@ -11,7 +11,8 @@ custom_field_value_container.with_row(mb: 1) do render OpenProject::Common::AttributeLabelComponent.new( attribute: @project_custom_field.attribute_name, - model: @project + model: @project, + required: @project_custom_field.required? ) do render(Primer::Beta::Text.new(font_weight: :bold)) { @project_custom_field.name } end diff --git a/spec/components/open_project/common/attribute_label_component_spec.rb b/spec/components/open_project/common/attribute_label_component_spec.rb index 4c0b58602f9..137c87c5d81 100644 --- a/spec/components/open_project/common/attribute_label_component_spec.rb +++ b/spec/components/open_project/common/attribute_label_component_spec.rb @@ -35,12 +35,13 @@ RSpec.describe OpenProject::Common::AttributeLabelComponent, type: :component do let(:attribute) { "name" } let(:model) { create(:project) } + let(:required) { false } let(:tag) { :span } let(:current_user) { create(:user) } let(:content) { "Name" } subject do - render_inline(described_class.new(attribute:, model:, tag:, current_user:)) do + render_inline(described_class.new(attribute:, model:, tag:, current_user:, required:)) do content end @@ -67,6 +68,14 @@ RSpec.describe OpenProject::Common::AttributeLabelComponent, type: :component do it "renders content" do expect(subject).to have_text "Name" end + + context "with a required field" do + let(:required) { true } + + it "renders a required star" do + expect(subject).to have_text "*" + end + end end context "without help text" do