Skip to content

Commit

Permalink
Add aria-haspopup and aria-expanded to invoker (#2989)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoyceZhu authored Aug 6, 2024
1 parent 3bf8fd4 commit 36a044a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tall-ladybugs-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Add `aria-haspopup` and `aria-expanded` to `SelectPanel` state
2 changes: 1 addition & 1 deletion app/components/primer/alpha/select_panel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def initialize(

system_arguments[:aria] = merge_aria(
system_arguments,
{ aria: { controls: "#{@panel_id}-dialog" } }
{ aria: { controls: "#{@panel_id}-dialog", "haspopup": "dialog", "expanded": "false" } }
)

Primer::Beta::Button.new(**system_arguments)
Expand Down
3 changes: 3 additions & 0 deletions app/components/primer/alpha/select_panel_element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const updateWhenVisible = (() => {
})
resizeObserver.observe(el.ownerDocument.documentElement)
el.addEventListener('dialog:close', () => {
el.invokerElement?.setAttribute('aria-expanded', 'false')
anchors.delete(el)
})
el.addEventListener('dialog:open', () => {
Expand Down Expand Up @@ -466,6 +467,7 @@ export class SelectPanelElement extends HTMLElement {
if (event.target === this.dialog && event.type === 'close') {
// Remove data-ready so it can be set the next time the panel is opened
this.dialog.removeAttribute('data-ready')
this.invokerElement?.setAttribute('aria-expanded', 'false')

this.dispatchEvent(
new CustomEvent('panelClosed', {
Expand Down Expand Up @@ -908,6 +910,7 @@ export class SelectPanelElement extends HTMLElement {
show() {
this.updateAnchorPosition()
this.dialog.showModal()
this.invokerElement?.setAttribute('aria-expanded', 'true')
const event = new CustomEvent('dialog:open', {
detail: {dialog: this.dialog},
})
Expand Down

0 comments on commit 36a044a

Please sign in to comment.