Skip to content

Commit

Permalink
WIP - A11y improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
myabc committed Feb 5, 2025
1 parent 54762ad commit 48d629d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
9 changes: 8 additions & 1 deletion app/components/primer/open_project/danger_dialog.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
</scrollable-region>
<%= render(Primer::Alpha::Dialog::Footer.new(show_divider: false)) do %>
<%= render(Primer::Beta::Button.new(data: { "close-dialog-id": dialog_id })) { @cancel_button_text } %>
<%= render(Primer::Beta::Button.new(type: (@form_wrapper.shows_form? ? :submit : :button), scheme: :danger, data: { "submit-dialog-id": dialog_id })) { @confirm_button_text } %>
<%= render(Primer::Beta::Button.new(
id: @confirm_button_id,
type: (@form_wrapper.shows_form? ? :submit : :button),
scheme: :danger,
role: :region,
data: { "submit-dialog-id": dialog_id },
aria: { live: "polite" }
)) { @confirm_button_text } %>
<% end %>
<% end %>
</danger-dialog-form-helper>
Expand Down
8 changes: 7 additions & 1 deletion app/components/primer/open_project/danger_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ class DangerDialog < Primer::Component

check_box_id = "#{dialog_id}-check_box"

Primer::OpenProject::DangerDialog::ConfirmationCheckBox.new(check_box_id: check_box_id, check_box_name: @check_box_name, **system_arguments)
Primer::OpenProject::DangerDialog::ConfirmationCheckBox.new(
confirm_button_id: @confirm_button_id,
check_box_id: check_box_id,
check_box_name: @check_box_name,
**system_arguments)
}

# Optional additional details, such as grid displaying a list of items to be deleted
Expand Down Expand Up @@ -79,6 +83,7 @@ def initialize(
@form_wrapper = FormWrapper.new(**form_arguments)
@dialog_id = id.to_s

@confirm_button_id = "#{@dialog_id}-confirm-button"
@confirm_button_text = confirm_button_text
@cancel_button_text = cancel_button_text

Expand All @@ -88,6 +93,7 @@ def initialize(
system_arguments[:classes],
"DangerDialog"
)
@system_arguments[:role] = "alertdialog"

@dialog = Primer::Alpha::Dialog.new(title: title, subtitle: nil, visually_hide_title: true, **@system_arguments)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class DangerDialog
class ConfirmationCheckBox < Primer::Component
status :open_project

# @param confirm_button_id [String] The id of the confirm button.
# @param check_box_id [String] The id of the check_box input.
# @param check_box_name [String] The name of the check_box input.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(check_box_id: self.class.generate_id, check_box_name:, **system_arguments)
def initialize(confirm_button_id:, check_box_id: self.class.generate_id, check_box_name:, **system_arguments)
@system_arguments = deny_tag_argument(**system_arguments)
@system_arguments[:tag] = :div
@system_arguments[:classes] = class_names(
Expand All @@ -26,6 +27,8 @@ def initialize(check_box_id: self.class.generate_id, check_box_name:, **system_a
target: "danger-dialog-form-helper.checkbox",
action: "change:danger-dialog-form-helper#toggle"
}
@check_box_arguments[:autofocus] = true
@check_box_arguments[:aria] = merge_aria(@check_box_arguments, { aria: { controls: confirm_button_id } })
end

def call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ class DangerDialogFormHelperElement extends HTMLElement {
toggle(): void {
if (this.checkbox) {
this.submitButton.disabled = !this.checkbox.checked
this.submitButton.ariaDisabled = String(!this.checkbox.checked)
}
}

#reset(): void {
if (this.checkbox) {
this.checkbox.disabled = false
}
this.toggle()
}
}
Expand Down

0 comments on commit 48d629d

Please sign in to comment.