Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActionMenu: Move aria-checked to button #2060

Merged
merged 2 commits into from
Jun 7, 2023
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/gorgeous-paws-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': minor
---

ActionMenu: Move aria-checked to button
178 changes: 89 additions & 89 deletions app/components/primer/alpha/action_list.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -158,95 +158,6 @@
}
}

/*
* checkbox item [aria-checked]
* listbox [aria-selected]
*/
&[aria-checked='true'],
&[aria-selected='true'] {
/* multiselect checkmark */
& .ActionListItem-multiSelectCheckmark {
visibility: visible;
opacity: 1;
transition: visibility 0 linear 0, opacity 50ms;
}

/* singleselect checkmark */
& .ActionListItem-singleSelectCheckmark {
visibility: visible;

@media screen and (prefers-reduced-motion: no-preference) {
animation: checkmarkIn 200ms cubic-bezier(0.11, 0, 0.5, 0) forwards;
@keyframes checkmarkIn {
from {
clip-path: inset(16px 0 0 0);
}

to {
clip-path: inset(0 0 0 0);
}
}
}
}

/* checkbox */
& .ActionListItem-multiSelectIcon {
& .ActionListItem-multiSelectIconRect {
fill: var(--color-accent-fg);
stroke: var(--color-accent-fg);
stroke-width: var(--borderWidth-thin, 1px);
}

& .ActionListItem-multiSelectCheckmark {
fill: var(--color-fg-on-emphasis);
}
}
}

&[aria-checked='false'],
&[aria-selected='false'] {
/* multiselect checkmark */
& .ActionListItem-multiSelectCheckmark {
visibility: hidden;
opacity: 0;
transition: visibility 0 linear 50ms, opacity 50ms;
}

/* singleselect checkmark */
& .ActionListItem-singleSelectCheckmark {
visibility: hidden;
transition: visibility 0s linear 200ms;
clip-path: inset(16px 0 0 0);

@media screen and (prefers-reduced-motion: no-preference) {
animation: checkmarkOut 200ms cubic-bezier(0.11, 0, 0.5, 0) forwards;
@keyframes checkmarkOut {
from {
clip-path: inset(0 0 0 0);
}

to {
clip-path: inset(16px 0 0 0);
}
}
}
}

/* checkbox */
& .ActionListItem-multiSelectIcon {
& .ActionListItem-multiSelectIconRect {
fill: var(--color-canvas-default);
stroke: var(--color-border-default);
stroke-width: var(--borderWidth-thin, 1px);
}
}

& .ActionListItem-multiSelectIconRect {
fill: var(--color-canvas-default);
border: var(--borderWidth-thin, 1px) solid var(--color-border-default);
}
}

/* Autocomplete [aria-selected] items */

&[aria-selected='true'] {
Expand Down Expand Up @@ -503,6 +414,95 @@
}
}

/*
* checkbox item [aria-checked]
* listbox [aria-selected]
*/
&[aria-checked='true'],
&[aria-selected='true'] {
/* multiselect checkmark */
& .ActionListItem-multiSelectCheckmark {
visibility: visible;
opacity: 1;
transition: visibility 0 linear 0, opacity 50ms;
}

/* singleselect checkmark */
& .ActionListItem-singleSelectCheckmark {
visibility: visible;

@media screen and (prefers-reduced-motion: no-preference) {
animation: checkmarkIn 200ms cubic-bezier(0.11, 0, 0.5, 0) forwards;
@keyframes checkmarkIn {
from {
clip-path: inset(16px 0 0 0);
}

to {
clip-path: inset(0 0 0 0);
}
}
}
}

/* checkbox */
& .ActionListItem-multiSelectIcon {
& .ActionListItem-multiSelectIconRect {
fill: var(--color-accent-fg);
stroke: var(--color-accent-fg);
stroke-width: var(--borderWidth-thin, 1px);
}

& .ActionListItem-multiSelectCheckmark {
fill: var(--color-fg-on-emphasis);
}
}
}

&[aria-checked='false'],
&[aria-selected='false'] {
/* multiselect checkmark */
& .ActionListItem-multiSelectCheckmark {
visibility: hidden;
opacity: 0;
transition: visibility 0 linear 50ms, opacity 50ms;
}

/* singleselect checkmark */
& .ActionListItem-singleSelectCheckmark {
visibility: hidden;
transition: visibility 0s linear 200ms;
clip-path: inset(16px 0 0 0);

@media screen and (prefers-reduced-motion: no-preference) {
animation: checkmarkOut 200ms cubic-bezier(0.11, 0, 0.5, 0) forwards;
@keyframes checkmarkOut {
from {
clip-path: inset(0 0 0 0);
}

to {
clip-path: inset(16px 0 0 0);
}
}
}
}

/* checkbox */
& .ActionListItem-multiSelectIcon {
& .ActionListItem-multiSelectIconRect {
fill: var(--color-canvas-default);
stroke: var(--color-border-default);
stroke-width: var(--borderWidth-thin, 1px);
}
}

& .ActionListItem-multiSelectIconRect {
fill: var(--color-canvas-default);
border: var(--borderWidth-thin, 1px) solid var(--color-border-default);
}
}

/* sizes */

&.ActionListContent--sizeLarge {
Expand Down
4 changes: 2 additions & 2 deletions app/components/primer/alpha/action_list/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def initialize(

def before_render
if @list.allows_selection?
@system_arguments[:aria] = merge_aria(
@system_arguments,
@content_arguments[:aria] = merge_aria(
@content_arguments,
{ aria: { checked: active? } }
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,13 @@ export class ActionMenuElement extends HTMLElement {
if (event.type === 'focusout' && !this.contains((event as FocusEvent).relatedTarget as Node)) {
this.popoverElement?.hidePopover()
} else if (this.#isActivationKeydown(event) || (event instanceof MouseEvent && event.type === 'click')) {
const item = (event.target as Element).closest(menuItemSelectors.join(','))?.closest('li')
const item = (event.target as Element).closest(menuItemSelectors.join(','))
if (!item) return
const ariaChecked = item.getAttribute('aria-checked')
const checked = ariaChecked !== 'true'
item.setAttribute('aria-checked', `${checked}`)
if (this.selectVariant === 'single') {
const selector = menuItemSelectors.map(s => `li[aria-checked] ${s}`).join(',')
for (const checkedItemContent of this.querySelectorAll(selector)) {
const checkedItem = checkedItemContent.closest('li')!
for (const checkedItem of this.querySelectorAll('[aria-checked]')) {
if (checkedItem !== item) {
checkedItem.setAttribute('aria-checked', 'false')
}
Expand Down
7 changes: 6 additions & 1 deletion app/components/primer/alpha/action_menu/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ActionMenu
# used as a standalone component.
class List < Primer::Alpha::ActionList
DEFAULT_ITEM_TAG = :button
ITEM_TAG_OPTIONS = [:a, :button, :"clipboard-copy", DEFAULT_ITEM_TAG].freeze
ITEM_TAG_OPTIONS = [:a, :"clipboard-copy", DEFAULT_ITEM_TAG].freeze

# Adds a new item to the list.
#
Expand All @@ -35,6 +35,11 @@ def with_item(data: {}, **system_arguments, &block)
content_arguments[:tabindex] = -1
system_arguments[:autofocus] = "" if system_arguments[:autofocus]

content_arguments[:data] = merge_data(
content_arguments,
{ data: { value: data.delete(:value) || system_arguments.delete(:"data-value") } }
)

if system_arguments[:disabled]
content_arguments[:aria] = merge_aria(
content_arguments,
Expand Down
8 changes: 4 additions & 4 deletions test/system/alpha/action_menu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def test_single_select_form_submission

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
assert_equal response["value"], "fast_forward"
assert_equal "fast_forward", response["value"]
end

def test_single_select_form_uses_label_if_no_value_provided
Expand All @@ -178,7 +178,7 @@ def test_single_select_form_uses_label_if_no_value_provided

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
assert_equal response["value"], "Resolve"
assert_equal "Resolve", response["value"]
end

def test_multiple_select_form_submission
Expand All @@ -195,7 +195,7 @@ def test_multiple_select_form_submission

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
assert_equal response["value"], %w[fast_forward recursive]
assert_equal %w[fast_forward recursive], response["value"]
end

def test_multiple_select_form_uses_label_if_no_value_provided
Expand All @@ -212,7 +212,7 @@ def test_multiple_select_form_uses_label_if_no_value_provided

# for some reason the JSON response is wrapped in HTML, I have no idea why
response = JSON.parse(find("pre").text)
assert_equal response["value"], %w[fast_forward Resolve]
assert_equal %w[fast_forward Resolve], response["value"]
end

def test_individual_items_can_submit_post_requests_via_forms
Expand Down