mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Allow required star to be shown for AttributeLabelComponent
This commit is contained in:
@@ -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 %>
|
||||
|
||||
@@ -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))
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user