Skip to content

Commit

Permalink
Allow form buttons to be disabled on click via data-disable-with (#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Jul 31, 2023
1 parent 1b8ff1b commit 9334445
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changeset/curly-waves-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/view-components': patch
---

Allow form buttons to be disabled on click with data-disable-with

<!-- Changed components: Primer::Alpha::FormButton -->
2 changes: 1 addition & 1 deletion app/forms/submit_button_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SubmitButtonForm < ApplicationForm
)

my_form.group(layout: :horizontal) do |button_group|
button_group.submit(name: :submit, label: "Submit", scheme: :primary, mb: 3) do |component|
button_group.submit(name: :submit, label: "Submit", scheme: :primary, mb: 3, disabled: true) do |component|
component.with_leading_visual_icon(icon: :"check-circle")
end

Expand Down
7 changes: 3 additions & 4 deletions lib/primer/forms/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ def initialize(input:, type: :button)
# rails uses a string for this, but PVC wants a symbol
@input.merge_input_arguments!(type: type.to_sym)

# Never disable buttons. This overrides the global
# ActionView::Base.automatically_disable_submit_tag setting.
# Disabling buttons is not accessible.
@input.remove_input_data(:disable_with)
# Never allow buttons to be disabled. Disabling buttons is not accessible.
# See: https://primer.style/design/ui-patterns/saving#state
@input.input_arguments.delete(:disabled)
end

def input_arguments
Expand Down
2 changes: 2 additions & 0 deletions lib/primer/forms/dsl/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,11 @@ def add_input_data(key, value)
input_data[key] = value
end

# :nocov:
def remove_input_data(key)
input_data.delete(key)
end
# :nocov:

def merge_input_arguments!(arguments)
arguments.each do |k, v|
Expand Down
4 changes: 2 additions & 2 deletions test/lib/primer/forms_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def test_renders_buttons_with_slots
end
end

def test_renders_a_submit_button_without_data_disable_with
def test_disallows_disabled_buttons
render_preview :submit_button_form

button = page.find_all("button[type=submit]").first
assert_nil button["data-disable-with"]
assert_nil button["disabled"]
end

def test_renders_buttons_with_primer_utility_margins
Expand Down

0 comments on commit 9334445

Please sign in to comment.