Skip to content

Commit 1d0ecc5

Browse files
authored
Bug Fix: anchored-position re-calculate position on scroll (#2794)
1 parent e478884 commit 1d0ecc5

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

.changeset/brown-buckets-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/view-components": patch
3+
---
4+
5+
Fix: Re-calculate anchored-position on scroll

app/components/primer/anchored_position.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const updateWhenVisible = (() => {
1313
return (el: AnchoredPositionElement) => {
1414
// eslint-disable-next-line github/prefer-observers
1515
window.addEventListener('resize', updateVisibleAnchors)
16+
// eslint-disable-next-line github/prefer-observers
17+
window.addEventListener('scroll', updateVisibleAnchors)
1618
intersectionObserver ||= new IntersectionObserver(entries => {
1719
for (const entry of entries) {
1820
const target = entry.target as AnchoredPositionElement

previews/primer/alpha/overlay_preview.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ def overlay_with_header_filter
187187
def overlay_with_three_bodies
188188
render_with_template(locals: {})
189189
end
190+
191+
def in_a_sticky_container
192+
render_with_template(locals: {})
193+
end
190194
end
191195
end
192196
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div style="position:sticky;top:0;" class="color-bg-accent">
2+
<%= render(Primer::Alpha::Overlay.new(title: "Dialog", role: :dialog, size: :large, padding: :condensed)) do |d| %>
3+
<% d.with_header(title: "Large Dialog Header", divider: true) do |header| %>
4+
<% header.with_filter do %>
5+
<%= render Primer::Alpha::TextField.new(
6+
autofocus: true,
7+
visually_hide_label:
8+
true,
9+
name: "filter",
10+
label: "Filter Overlay"
11+
) %>
12+
<% end %>
13+
<% end %>
14+
<% d.with_show_button { "Show Overlay" } %>
15+
<% d.with_footer { "Large Dialog Footer" } %>
16+
<% d.with_body { "This is a long body for the overlay dialog. <br>".html_safe * 20 } %>
17+
<% end %>
18+
</div>
19+
<div style="height:3000px;"></div>

0 commit comments

Comments
 (0)