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

ensure scroll position does not change when opening actionmenu #2411

Merged
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/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>
Loading