Skip to content

Commit

Permalink
Make text field and other form inputs respect the full_width: option (
Browse files Browse the repository at this point in the history
#2673)

Co-authored-by: camertron <[email protected]>
  • Loading branch information
camertron and camertron authored Mar 12, 2024
1 parent 53a3390 commit 3a6762d
Show file tree
Hide file tree
Showing 59 changed files with 35 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-onions-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

Make text field and other form inputs respect the full_width: option
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lib/primer/forms/dsl/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Input
# @param size [Symbol] The size of the field. <%= one_of(Primer::Forms::Dsl::Input::SIZE_OPTIONS) %>

# @!macro [new] form_full_width_arguments
# @param full_width [Boolean] When set to `true`, the field will take up all the horizontal space allowed by its container.
# @param full_width [Boolean] When set to `true`, the field will take up all the horizontal space allowed by its container. Defaults to `true`.

# @!macro [new] form_system_arguments
# @param system_arguments [Hash] A hash of attributes passed to the underlying Rails builder methods. These options may mean something special depending on the type of input, otherwise they are emitted as HTML attributes. See the [Rails documentation](https://guides.rubyonrails.org/form_helpers.html) for more information. In addition, the usual Primer utility arguments are accepted in system arguments. For example, passing `mt: 2` will add the `mt-2` class to the input. See the Primer system arguments docs for details.
Expand Down Expand Up @@ -73,7 +73,7 @@ def initialize(builder:, form:, **system_arguments)
@caption = @input_arguments.delete(:caption)
@validation_message = @input_arguments.delete(:validation_message)
@invalid = @input_arguments.delete(:invalid)
@full_width = @input_arguments.delete(:full_width)
@full_width = @input_arguments.delete(:full_width) { true }
@size = @input_arguments.delete(:size)

# If scope_name_to_model is false, the name of the input for eg. `my_field`
Expand Down
3 changes: 1 addition & 2 deletions lib/primer/forms/form_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def initialize(input:, tag: :div, **system_arguments)
system_arguments[:class],
system_arguments[:classes],
"FormControl",
"width-full",
"FormControl--fullWidth" => @input.full_width?
"width-full FormControl--fullWidth" => @input.full_width?
)
}

Expand Down
1 change: 1 addition & 0 deletions lib/primer/forms/select.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
<%= builder.select(@input.name, options, @input.select_arguments, **@input.input_arguments) %>
<% end %>
<% end %>

13 changes: 12 additions & 1 deletion previews/primer/alpha/select_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def playground(
required: false,
visually_hide_label: false,
size: Primer::Forms::Dsl::Input::DEFAULT_SIZE.to_s,
full_width: false,
full_width: true,
disabled: false,
invalid: false,
validation_message: nil
Expand Down Expand Up @@ -97,6 +97,17 @@ def full_width
end
end

# @label Not full width
# @snapshot
def not_full_width
render(Primer::Alpha::Select.new(full_width: false, name: "my-select-list", label: "Favorite place to visit")) do |component|
component.option(label: "Lopez Island", value: "lopez")
component.option(label: "Shaw Island", value: "shaw")
component.option(label: "Orcas Island", value: "orcas")
component.option(label: "San Juan Island", value: "san_juan")
end
end

# @label Disabled
# @snapshot
def disabled
Expand Down
8 changes: 7 additions & 1 deletion previews/primer/alpha/text_area_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def playground(
caption: "You can trust me, I'm a website",
required: false,
visually_hide_label: false,
full_width: false,
full_width: true,
disabled: false,
invalid: false,
validation_message: nil
Expand Down Expand Up @@ -70,6 +70,12 @@ def full_width
render(Primer::Alpha::TextArea.new(full_width: true, name: "my-text-area", label: "Tell me about yourself"))
end

# @label Not full width
# @snapshot
def not_full_width
render(Primer::Alpha::TextArea.new(full_width: false, name: "my-text-area", label: "Tell me about yourself"))
end

# @label Disabled
# @snapshot
def disabled
Expand Down
8 changes: 7 additions & 1 deletion previews/primer/alpha/text_field_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def playground(
size: Primer::Forms::Dsl::Input::DEFAULT_SIZE.to_s,
show_clear_button: false,
clear_button_id: "my-text-field-clear-button",
full_width: false,
full_width: true,
disabled: false,
invalid: false,
validation_message: nil,
Expand Down Expand Up @@ -125,6 +125,12 @@ def full_width
render(Primer::Alpha::TextField.new(full_width: true, name: "my-text-field", label: "My text field"))
end

# @label Not full width
# @snapshot
def not_full_width
render(Primer::Alpha::TextField.new(full_width: false, name: "my-text-field", label: "My text field"))
end

# @label Disabled
# @snapshot
def disabled
Expand Down

0 comments on commit 3a6762d

Please sign in to comment.