Skip to content

Commit

Permalink
Fix bug in ActionMenu button where return doesn't trigger menu (#2158)
Browse files Browse the repository at this point in the history
Co-authored-by: Keith Cirkel <[email protected]>
Co-authored-by: Cameron Dutro <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent c1e5192 commit 0afaecc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/gold-dingos-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@primer/view-components": patch
---

Fix bug in ActionMenu button where return doesn't trigger menu

<!-- Changed components: Primer::Alpha::ActionMenu -->
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {controller, target} from '@github/catalyst'
import IncludeFragmentElement from '@github/include-fragment-element'
import '@oddbird/popover-polyfill'
import type {IncludeFragmentElement} from '@github/include-fragment-element'

type SelectVariant = 'none' | 'single' | 'multiple' | null
type SelectedItem = {
Expand Down Expand Up @@ -49,14 +50,14 @@ export class ActionMenuElement extends HTMLElement {
}

get popoverElement(): HTMLElement | null {
return this.querySelector<HTMLElement>('[popover]')
return this.invokerElement?.popoverTargetElement || null
}

get invokerElement(): HTMLElement | null {
get invokerElement(): HTMLButtonElement | null {
const id = this.querySelector('[role=menu]')?.id
if (!id) return null
for (const el of this.querySelectorAll(`[aria-controls]`)) {
if (el.getAttribute('aria-controls') === id) return el as HTMLElement
if (el.getAttribute('aria-controls') === id) return el as HTMLButtonElement
}
return null
}
Expand Down
12 changes: 12 additions & 0 deletions test/system/alpha/action_menu_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ def test_action_keydown
end
end

def test_action_keydown_on_icon_button
visit_preview(:with_icon_button)

page.evaluate_script(<<~JS)
document.querySelector('action-menu button[aria-controls]').focus()
JS

page.driver.browser.keyboard.type(:enter)

assert_selector "anchored-position"
end

def test_action_anchor
visit_preview(:with_actions)

Expand Down

0 comments on commit 0afaecc

Please sign in to comment.