Skip to content

Commit 3249011

Browse files
feat: update to upstream @floating-ui/dom@1.7.6 (#278)
* feat: update to upstream @floating-ui/dom@1.7.6 * feat(dom): allow not passing a floating element to `auto_update` --------- Co-authored-by: rust-for-web[bot] <191031261+rust-for-web[bot]@users.noreply.github.com> Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
1 parent 5a07bfa commit 3249011

7 files changed

Lines changed: 67 additions & 40 deletions

File tree

packages/dioxus/src/use_auto_update.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ use crate::{ShallowRc, types::WhileElementsMountedFn};
1111
pub fn use_auto_update() -> Memo<ShallowRc<WhileElementsMountedFn>> {
1212
use_memo(|| {
1313
let rc: Rc<WhileElementsMountedFn> = Rc::new(|reference, floating, update| {
14-
auto_update(reference, floating, update, AutoUpdateOptions::default())
14+
auto_update(
15+
reference,
16+
Some(floating),
17+
update,
18+
AutoUpdateOptions::default(),
19+
)
1520
});
1621

1722
rc.into()
@@ -28,7 +33,7 @@ pub fn use_auto_update_with_options(
2833
let options = options();
2934

3035
let rc: Rc<WhileElementsMountedFn> = Rc::new(move |reference, floating, update| {
31-
auto_update(reference, floating, update, options.clone())
36+
auto_update(reference, Some(floating), update, options.clone())
3237
});
3338

3439
rc.into()

packages/dom/src/auto_update.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl AutoUpdateOptions {
254254
/// Should only be called when the floating element is mounted on the DOM or visible on the screen.
255255
pub fn auto_update(
256256
reference: ElementOrVirtual,
257-
floating: &Element,
257+
floating: Option<&Element>,
258258
update: Rc<dyn Fn()>,
259259
options: AutoUpdateOptions,
260260
) -> Box<dyn Fn()> {
@@ -278,7 +278,9 @@ pub fn auto_update(
278278
ancestors = get_overflow_ancestors(reference, ancestors, true);
279279
}
280280

281-
ancestors.append(&mut get_overflow_ancestors(floating, vec![], true));
281+
if let Some(floating) = floating {
282+
ancestors.append(&mut get_overflow_ancestors(floating, vec![], true));
283+
}
282284

283285
ancestors
284286
} else {
@@ -327,16 +329,18 @@ pub fn auto_update(
327329
let resize_observer: Rc<RefCell<Option<ResizeObserver>>> = Rc::new(RefCell::new(None));
328330

329331
if element_resize {
330-
let reobserve_floating = floating.clone();
331332
let reobserve_closure: Rc<Closure<dyn FnMut()>> = Rc::new(Closure::new({
333+
let floating = floating.cloned();
332334
let resize_observer = resize_observer.clone();
333335

334336
move || {
335-
resize_observer
336-
.borrow()
337-
.as_ref()
338-
.expect("Resize observer should exist.")
339-
.observe(&reobserve_floating);
337+
if let Some(floating) = floating.as_ref() {
338+
resize_observer
339+
.borrow()
340+
.as_ref()
341+
.expect("Resize observer should exist.")
342+
.observe(floating);
343+
}
340344
}
341345
}));
342346

@@ -378,11 +382,13 @@ pub fn auto_update(
378382
.observe(reference);
379383
}
380384

381-
resize_observer
382-
.borrow()
383-
.as_ref()
384-
.expect("Resize observer should exist.")
385-
.observe(floating);
385+
if let Some(floating) = floating {
386+
resize_observer
387+
.borrow()
388+
.as_ref()
389+
.expect("Resize observer should exist.")
390+
.observe(floating);
391+
}
386392
}
387393

388394
let frame_id: Rc<RefCell<Option<i32>>> = Rc::new(RefCell::new(None));

packages/dom/src/platform/get_clipping_rect.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -193,25 +193,25 @@ pub fn get_clipping_rect(
193193
.chain(vec![ElementOrRootBoundary::RootBoundary(root_boundary)])
194194
.collect();
195195

196-
let init =
196+
let first_rect =
197197
get_client_rect_from_clipping_ancestor(element, clipping_ancestors[0].clone(), strategy);
198-
let clipping_rect = clipping_ancestors
199-
.into_iter()
200-
.fold(init, |mut acc, clipping_ancestor| {
201-
let rect = get_client_rect_from_clipping_ancestor(element, clipping_ancestor, strategy);
202-
203-
acc.top = acc.top.max(rect.top);
204-
acc.right = acc.right.min(rect.right);
205-
acc.bottom = acc.bottom.min(rect.bottom);
206-
acc.left = acc.left.max(rect.left);
207-
208-
acc
209-
});
198+
let mut top = first_rect.top;
199+
let mut right = first_rect.right;
200+
let mut bottom = first_rect.bottom;
201+
let mut left = first_rect.left;
202+
203+
for clipping_ancestor in clipping_ancestors.into_iter().skip(1) {
204+
let rect = get_client_rect_from_clipping_ancestor(element, clipping_ancestor, strategy);
205+
top = top.max(rect.top);
206+
right = right.min(rect.right);
207+
bottom = bottom.min(rect.bottom);
208+
left = left.max(rect.left);
209+
}
210210

211211
Rect {
212-
x: clipping_rect.left,
213-
y: clipping_rect.top,
214-
width: clipping_rect.right - clipping_rect.left,
215-
height: clipping_rect.bottom - clipping_rect.top,
212+
x: left,
213+
y: top,
214+
width: right - left,
215+
height: bottom - top,
216216
}
217217
}

packages/leptos/src/types.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ impl UseFloatingOptions {
9393
pub fn while_elements_mounted_auto_update(self) -> Self {
9494
let auto_update_rc: SendWrapper<Rc<WhileElementsMountedFn>> =
9595
SendWrapper::new(Rc::new(|reference, floating, update| {
96-
auto_update(reference, floating, update, AutoUpdateOptions::default())
96+
auto_update(
97+
reference,
98+
Some(floating),
99+
update,
100+
AutoUpdateOptions::default(),
101+
)
97102
}));
98103
self.while_elements_mounted(auto_update_rc)
99104
}
@@ -102,7 +107,12 @@ impl UseFloatingOptions {
102107
pub fn while_elements_mounted_auto_update_with_enabled(self, enabled: Signal<bool>) -> Self {
103108
let auto_update_rc: SendWrapper<Rc<WhileElementsMountedFn>> =
104109
SendWrapper::new(Rc::new(|reference, floating, update| {
105-
auto_update(reference, floating, update, AutoUpdateOptions::default())
110+
auto_update(
111+
reference,
112+
Some(floating),
113+
update,
114+
AutoUpdateOptions::default(),
115+
)
106116
}));
107117
self.while_elements_mounted(MaybeProp::derive(move || {
108118
if enabled.get() {
@@ -121,7 +131,7 @@ impl UseFloatingOptions {
121131
let auto_update_rc =
122132
move |options: AutoUpdateOptions| -> SendWrapper<Rc<WhileElementsMountedFn>> {
123133
SendWrapper::new(Rc::new(move |reference, floating, update| {
124-
auto_update(reference, floating, update, options.clone())
134+
auto_update(reference, Some(floating), update, options.clone())
125135
}))
126136
};
127137

@@ -139,7 +149,7 @@ impl UseFloatingOptions {
139149
let auto_update_rc =
140150
move |options: AutoUpdateOptions| -> SendWrapper<Rc<WhileElementsMountedFn>> {
141151
SendWrapper::new(Rc::new(move |reference, floating, update| {
142-
auto_update(reference, floating, update, options.clone())
152+
auto_update(reference, Some(floating), update, options.clone())
143153
}))
144154
};
145155

packages/leptos/tests/visual/src/spec/auto_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ pub fn AutoUpdate() -> impl IntoView {
9393

9494
cleanup.set_value(Some(SendWrapper::new(auto_update(
9595
(&reference).into(),
96-
&floating,
96+
Some(&floating),
9797
(*update).clone(),
9898
options
9999
.get()

packages/yew/src/use_auto_update.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ use crate::types::WhileElementsMountedFn;
1212
pub fn use_auto_update() -> Rc<Rc<WhileElementsMountedFn>> {
1313
use_memo((), |_| {
1414
let rc: Rc<WhileElementsMountedFn> = Rc::new(|reference, floating, update| {
15-
auto_update(reference, floating, update, AutoUpdateOptions::default()).into()
15+
auto_update(
16+
reference,
17+
Some(floating),
18+
update,
19+
AutoUpdateOptions::default(),
20+
)
21+
.into()
1622
});
1723

1824
rc
@@ -28,7 +34,7 @@ pub fn use_auto_update_with_options(options: AutoUpdateOptions) -> Rc<Rc<WhileEl
2834
let options = options.clone();
2935

3036
let rc: Rc<WhileElementsMountedFn> = Rc::new(move |reference, floating, update| {
31-
auto_update(reference, floating, update, options.clone()).into()
37+
auto_update(reference, Some(floating), update, options.clone()).into()
3238
});
3339

3440
rc

upstream.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[releases]
22
core = "1.7.5"
3-
dom = "1.7.4"
3+
dom = "1.7.6"
44
utils = "0.2.11"
55
vue = "1.1.9"

0 commit comments

Comments
 (0)