Skip to content

Commit

Permalink
Merge branch 'main' into fix_dialog_inside_menu
Browse files Browse the repository at this point in the history
  • Loading branch information
camertron authored Dec 15, 2023
2 parents 1945e77 + 58e700a commit d40b812
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tall-emus-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Ensure scroll position does not change when opening ActionMenus
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class ActionMenuElement extends HTMLElement {
this.addEventListener('mouseover', this, {signal})
this.addEventListener('focusout', this, {signal})
this.addEventListener('mousedown', this, {signal})
this.popoverElement?.addEventListener('toggle', this, {signal})
this.#setDynamicLabel()
this.#updateInput()
this.#softDisableItems()
Expand Down Expand Up @@ -182,6 +183,10 @@ export class ActionMenuElement extends HTMLElement {
const targetIsInvoker = this.invokerElement?.contains(event.target as HTMLElement)
const eventIsActivation = this.#isActivation(event)

if (event.type === 'toggle' && (event as ToggleEvent).newState === 'open') {
this.#firstItem?.focus()
}

if (targetIsInvoker && event.type === 'mousedown') {
this.#invokerBeingClicked = true
return
Expand Down Expand Up @@ -261,7 +266,6 @@ export class ActionMenuElement extends HTMLElement {
this.#hide()
} else {
this.#show()
this.#firstItem?.focus()
}
}

Expand Down
7 changes: 7 additions & 0 deletions previews/primer/alpha/action_menu_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,13 @@ def opens_dialog(menu_id: "menu-1")
})
end

# @label In Scoll container
#
def in_scroll_container
render_with_template()
end


# @label Align end
#
def align_end(menu_id: "menu-1")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div style="height: 400px"></div>

<div style="position: relative">
<%= render Primer::Alpha::ActionMenu.new(anchor_align: :end) do |c| %>
<% c.with_show_button { "Edit" } %>
<% c.with_item(tag: :button, type: "button", label: "Rename") %>
<% c.with_item(tag: :button, type: "button", scheme: :danger, label: "Remove") %>
<% end %>
</div>

<div style="height: 1400px"></div>

0 comments on commit d40b812

Please sign in to comment.