Skip to content

Commit aeb9443

Browse files
Update to upstream @floating-ui/dom@1.6.12 (#49)
* Update to upstream @floating-ui/dom@1.6.12 * Fix handling of relative html offset clipping rect --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Daniëlle Huisman <danielle@huisman.me>
1 parent 02d712c commit aeb9443

6 files changed

Lines changed: 45 additions & 18 deletions

packages/dom/src/platform/convert_offset_parent_relative_rect_to_viewport_relative_rect.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use floating_ui_utils::{
99
use web_sys::{Element, Window};
1010

1111
use crate::{
12-
platform::get_scale::get_scale, utils::get_bounding_client_rect::get_bounding_client_rect,
12+
platform::get_scale::get_scale,
13+
utils::{get_bounding_client_rect::get_bounding_client_rect, get_html_offset::get_html_offset},
1314
};
1415

1516
pub fn convert_offset_parent_relative_rect_to_viewport_relative_rect(
@@ -68,9 +69,15 @@ pub fn convert_offset_parent_relative_rect_to_viewport_relative_rect(
6869
}
6970
}
7071

72+
let html_offset = if !is_offset_parent_an_element && !is_fixed {
73+
get_html_offset(&document_element, &scroll, Some(true))
74+
} else {
75+
Coords::new(0.0)
76+
};
77+
7178
Rect {
72-
x: rect.x * scale.x - scroll.scroll_left * scale.x + offsets.x,
73-
y: rect.y * scale.y - scroll.scroll_top * scale.y + offsets.y,
79+
x: rect.x * scale.x - scroll.scroll_left * scale.x + offsets.x + html_offset.x,
80+
y: rect.y * scale.y - scroll.scroll_top * scale.y + offsets.y + html_offset.y,
7481
width: rect.width * scale.x,
7582
height: rect.height * scale.y,
7683
}

packages/dom/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod get_bounding_client_rect;
22
pub mod get_css_dimensions;
33
pub mod get_document_rect;
4+
pub mod get_html_offset;
45
pub mod get_rect_relative_to_offset_parent;
56
pub mod get_viewport_rect;
67
pub mod get_visual_offsets;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use floating_ui_utils::{dom::NodeScroll, Coords};
2+
use web_sys::Element;
3+
4+
use crate::utils::get_window_scroll_bar_x::get_window_scroll_bar_x;
5+
6+
pub fn get_html_offset(
7+
document_element: &Element,
8+
scroll: &NodeScroll,
9+
ignore_scrollbar_x: Option<bool>,
10+
) -> Coords {
11+
let ignore_scrollbar_x = ignore_scrollbar_x.unwrap_or(false);
12+
13+
let html_rect = document_element.get_bounding_client_rect();
14+
let x = html_rect.left() + scroll.scroll_left
15+
- if ignore_scrollbar_x {
16+
0.0
17+
} else {
18+
// RTL <body> scrollbar.
19+
get_window_scroll_bar_x(document_element, Some(&html_rect))
20+
};
21+
let y = html_rect.top() + scroll.scroll_top;
22+
23+
Coords { x, y }
24+
}

packages/dom/src/utils/get_rect_relative_to_offset_parent.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use floating_ui_utils::{
99
use crate::{
1010
types::ElementOrVirtual,
1111
utils::{
12-
get_bounding_client_rect::get_bounding_client_rect,
12+
get_bounding_client_rect::get_bounding_client_rect, get_html_offset::get_html_offset,
1313
get_window_scroll_bar_x::get_window_scroll_bar_x,
1414
},
1515
};
@@ -59,19 +59,14 @@ pub fn get_rect_relative_to_offset_parent(
5959
}
6060
}
6161

62-
let mut html_x = 0.0;
63-
let mut html_y = 0.0;
62+
let html_offset = if !is_offset_parent_an_element && !is_fixed {
63+
get_html_offset(&document_element, &scroll, None)
64+
} else {
65+
Coords::new(0.0)
66+
};
6467

65-
if !is_offset_parent_an_element && !is_fixed {
66-
let html_rect = document_element.get_bounding_client_rect();
67-
html_y = html_rect.top() as f64 + scroll.scroll_top;
68-
html_x = html_rect.left()as f64 + scroll.scroll_left
69-
// RTL <body> scrollbar.
70-
- get_window_scroll_bar_x(&document_element, Some(html_rect));
71-
}
72-
73-
let x = rect.left + scroll.scroll_left - offsets.x - html_x;
74-
let y = rect.top + scroll.scroll_top - offsets.y - html_y;
68+
let x = rect.left + scroll.scroll_left - offsets.x - html_offset.x;
69+
let y = rect.top + scroll.scroll_top - offsets.y - html_offset.y;
7570

7671
Rect {
7772
x,

packages/dom/src/utils/get_window_scroll_bar_x.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use web_sys::{DomRect, Element};
44
use crate::utils::get_bounding_client_rect::get_bounding_client_rect;
55

66
// If <html> has a CSS width greater than the viewport, then this will be incorrect for RTL.
7-
pub fn get_window_scroll_bar_x(element: &Element, rect: Option<DomRect>) -> f64 {
7+
pub fn get_window_scroll_bar_x(element: &Element, rect: Option<&DomRect>) -> f64 {
88
let left_scroll = get_node_scroll(element.into()).scroll_left;
99

1010
if let Some(rect) = rect {

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.6.8"
3-
dom = "1.6.11"
3+
dom = "1.6.12"
44
utils = "0.2.8"
55
vue = "1.1.5"

0 commit comments

Comments
 (0)