Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/many-sheep-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openproject/primer-view-components': patch
---

Align Primer::OpenProject::InputGroup with error messages
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- text: My input group
- textbox "My input group": Copyable value
- button "Copy some text"
- text: Custom validation message
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/components/primer/open_project/input_group.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
<%= trailing_action %>
<% end %>

<% if @text_input_validation_message %>
<div class="FormControl-inlineValidation mt-1" id="<%= @text_input_validation_message_id %>">
<span class="FormControl-inlineValidation--visual">
<%= render(Primer::Beta::Octicon.new(icon: :"alert-fill", size: :xsmall, aria: { hidden: true })) %>
</span>
<span><%= @text_input_validation_message %></span>
</div>
<% end %>

<% if caption %>
<%= caption %>
<% end %>
Expand Down
13 changes: 13 additions & 0 deletions app/components/primer/open_project/input_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ class InputGroup < Primer::Component
renders_one :text_input, lambda { |readonly: true, **system_arguments|
deny_single_argument(:input_width, "Set the `input_width` on the `InputGroup`", **system_arguments)
deny_single_argument(:caption, "Set the `caption` on the `InputGroup`", **system_arguments)

# Extract validation_message so it can be rendered outside the flex row.
# This prevents the trailing action from misaligning when validation is present.
@text_input_validation_message = system_arguments.delete(:validation_message)
if @text_input_validation_message
@text_input_validation_message_id = self.class.generate_id(base_name: "input-group-validation")
system_arguments[:invalid] = true
system_arguments[:aria] = merge_aria(
system_arguments,
{ aria: { describedby: @text_input_validation_message_id } }
)
end

system_arguments[:input_width] = @system_arguments[:input_width]

system_arguments[:classes] = class_names(
Expand Down
9 changes: 9 additions & 0 deletions previews/primer/open_project/input_group_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ def with_caption
menu.with_caption { "Some caption" }
end
end

# @label With error message
# @snapshot
def with_error_message
render(Primer::OpenProject::InputGroup.new) do |menu|
menu.with_text_input(name: "a name", label: "My input group", validation_message: "Custom validation message", value: "Copyable value")
menu.with_trailing_action_clipboard_copy_button(id: "button", value: "Copyable value", aria: { label: "Copy some text" })
end
end
end
end
end
11 changes: 11 additions & 0 deletions test/components/primer/open_project/input_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def test_renders_caption
assert_selector(".FormControl-caption")
end

def test_renders_validation_message_outside_flex_row
render_inline(Primer::OpenProject::InputGroup.new) do |menu|
menu.with_text_input(name: "a name", label: "My input group", value: "Copyable value", validation_message: "Custom validation message")
menu.with_trailing_action_clipboard_copy_button(id: "button", value: "Copyable value", aria: { label: "Copy some text" })
end

validation_id = page.find(".InputGroup > .FormControl-inlineValidation", text: "Custom validation message")[:id]
assert_selector(%(.FormControl-input[aria-describedby~="#{validation_id}"]))
assert_selector(".FormControl-input[aria-invalid]")
end

def test_does_not_render_caption_from_system_argument
render_inline(Primer::OpenProject::InputGroup.new(caption: "Some caption")) do |menu|
menu.with_text_input(name: "a name", label: "My input group", value: "Copyable value")
Expand Down