Skip to content

Commit 2337359

Browse files
committed
[#71413] Upstream A11y improvements to DragHandle
Initial accessibility improvements, based on Backlogs implementation. `DragHandle` now renders the following additional attributes. - `role="button"` and `tabindex="0"` for button semantics, focusability. - `aria-label` (via a `label:` param) with a sensible default value. https://community.openproject.org/wp/57688
1 parent 2dce22b commit 2337359

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

app/components/primer/open_project/drag_handle.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,29 @@ class DragHandle < Primer::Component
1111
DEFAULT_SIZE = Primer::Beta::Octicon::SIZE_DEFAULT
1212
SIZE_OPTIONS = Primer::Beta::Octicon::SIZE_OPTIONS
1313

14+
# @param size [Symbol] <%= one_of(Primer::OpenProject::DragHandle::SIZE_OPTIONS) %>
15+
# @param label [String] String that can be read by assistive technology. A label should be short and concise. See the accessibility section for more information.
1416
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
15-
def initialize(size: Primer::OpenProject::DragHandle::DEFAULT_SIZE, **system_arguments)
16-
@system_arguments = system_arguments
17+
def initialize(size: Primer::OpenProject::DragHandle::DEFAULT_SIZE, label: I18n.t("drag_handle.button_drag"), **system_arguments)
18+
@system_arguments = deny_tag_argument(**system_arguments)
19+
20+
deny_aria_key(
21+
:label,
22+
"instead of `aria-label`, include `label` on the component initializer.",
23+
**@system_arguments
24+
)
1725
@system_arguments[:tag] = "div"
18-
@system_arguments[:classes] =
19-
class_names(
20-
@system_arguments[:classes],
21-
"DragHandle"
22-
)
26+
@system_arguments[:role] = "button"
27+
@system_arguments[:tabindex] = 0
28+
@system_arguments[:classes] = class_names(
29+
@system_arguments[:classes],
30+
"DragHandle"
31+
)
32+
33+
@system_arguments[:aria] = merge_aria(
34+
@system_arguments,
35+
aria: { label: label }
36+
)
2337

2438
@size = fetch_or_fallback(Primer::OpenProject::DragHandle::SIZE_OPTIONS, size, Primer::OpenProject::DragHandle::DEFAULT_SIZE)
2539
end

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ en:
88
button_filter: "Filter"
99
button_save: "Save"
1010

11+
drag_handle:
12+
button_drag: "Drag to reorder"
13+
1114
filterable_tree_view:
1215
filter_mode:
1316
all: "All"

static/arguments.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6030,6 +6030,18 @@
60306030
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/drag_handle.rb",
60316031
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/drag_handle/default/",
60326032
"parameters": [
6033+
{
6034+
"name": "size",
6035+
"type": "Symbol",
6036+
"default": "`:small`",
6037+
"description": "One of `:medium`, `:small`, or `:xsmall`."
6038+
},
6039+
{
6040+
"name": "label",
6041+
"type": "String",
6042+
"default": "`I18n.t(\"drag_handle.button_drag\")`",
6043+
"description": "String that can be read by assistive technology. A label should be short and concise. See the accessibility section for more information."
6044+
},
60336045
{
60346046
"name": "system_arguments",
60356047
"type": "Hash",

static/info_arch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19891,6 +19891,18 @@
1989119891
"source": "https://github.com/primer/view_components/tree/main/app/components/primer/open_project/drag_handle.rb",
1989219892
"lookbook": "https://primer.style/view-components/lookbook/inspect/primer/open_project/drag_handle/default/",
1989319893
"parameters": [
19894+
{
19895+
"name": "size",
19896+
"type": "Symbol",
19897+
"default": "`:small`",
19898+
"description": "One of `:medium`, `:small`, or `:xsmall`."
19899+
},
19900+
{
19901+
"name": "label",
19902+
"type": "String",
19903+
"default": "`I18n.t(\"drag_handle.button_drag\")`",
19904+
"description": "String that can be read by assistive technology. A label should be short and concise. See the accessibility section for more information."
19905+
},
1989419906
{
1989519907
"name": "system_arguments",
1989619908
"type": "Hash",

test/components/primer/open_project/drag_handle_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,36 @@ def test_renders_larger_icon
1616

1717
assert_selector(".DragHandle .octicon[width='24']")
1818
end
19+
20+
def test_renders_with_role_button
21+
render_inline(Primer::OpenProject::DragHandle.new)
22+
23+
assert_selector(".DragHandle[role='button']")
24+
end
25+
26+
def test_renders_with_tabindex
27+
render_inline(Primer::OpenProject::DragHandle.new)
28+
29+
assert_selector(".DragHandle[tabindex='0']")
30+
end
31+
32+
def test_renders_with_default_aria_label
33+
render_inline(Primer::OpenProject::DragHandle.new)
34+
35+
assert_selector(".DragHandle[aria-label='Drag to reorder']")
36+
end
37+
38+
def test_renders_with_custom_label
39+
render_inline(Primer::OpenProject::DragHandle.new(label: "Move item"))
40+
41+
assert_selector(".DragHandle[aria-label='Move item']")
42+
end
43+
44+
def test_denies_aria_label_argument
45+
with_raise_on_invalid_aria(true) do
46+
assert_raises(ArgumentError) do
47+
render_inline(Primer::OpenProject::DragHandle.new(aria: { label: "foo" }))
48+
end
49+
end
50+
end
1951
end

0 commit comments

Comments
 (0)