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/gold-clouds-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openproject/primer-view-components': patch
---

DangerDialog now uses the "alertdialog" ARIA role
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- button "Click me"
- dialog "Delete dialog":
- alertdialog "Delete dialog":
- heading "Delete dialog" [level=1]
- button "Close"
- heading "Delete this item?" [level=2]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- button "Click me"
- dialog "Delete dialog":
- alertdialog "Delete dialog":
- heading "Delete dialog" [level=1]
- button "Close"
- heading "Permanently delete this item?" [level=2]
Expand Down
3 changes: 3 additions & 0 deletions app/components/primer/open_project/danger_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ def initialize(
@confirm_button_text = confirm_button_text
@cancel_button_text = cancel_button_text

deny_single_argument(:role, "`role` will always be set to `alertdialog`.", **system_arguments)

@system_arguments = system_arguments
@system_arguments[:id] = @dialog_id
@system_arguments[:classes] = class_names(
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 @@ -22,9 +22,6 @@ class DangerDialogFormHelperElement extends HTMLElement {
}

#reset(): void {
if (this.checkbox) {
this.checkbox.disabled = false
}
this.toggle()
}
}
Expand Down
19 changes: 19 additions & 0 deletions test/components/primer/open_project/danger_dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def test_renders_default
end
end

def test_renders_alertdialog_role
render_inline(Primer::OpenProject::DangerDialog.new(title: "Danger action")) do |dialog|
dialog.with_confirmation_message do |message|
message.with_heading(tag: :h2) { "Danger" }
end
end

assert_selector("dialog[role=alertdialog]")
assert_selector("dialog[aria-modal=true]")
end

def test_renders_default_button_text
render_inline(Primer::OpenProject::DangerDialog.new(title: "Danger action")) do |dialog|
dialog.with_confirmation_message do |message|
Expand Down Expand Up @@ -97,6 +108,14 @@ def test_renders_with_confirmation_check_box_custom_button_text
end
end

def test_does_not_render_if_role_argument_provided
error = assert_raises(ArgumentError) do
render_inline(Primer::OpenProject::DangerDialog.new(title: "Invalid action", role: "button"))
end

assert_equal "`role` is an invalid argument. `role` will always be set to `alertdialog`.", error.message
end

def test_does_not_render_if_no_confirmation_message_provided
error = assert_raises(ArgumentError) do
render_inline(Primer::OpenProject::DangerDialog.new(title: "Danger action"))
Expand Down