mirror of
https://github.com/lexmount/moli.git
synced 2026-11-21 16:03:10 +00:00
fix(forms): preserve text input programmatic scroll
This commit is contained in:
@@ -617,7 +617,7 @@ where
|
||||
} else if world.is_viewport_defining_body(id) {
|
||||
false
|
||||
} else {
|
||||
world.boxes[id.index()].style.establishes_scroll_container()
|
||||
world.boxes[id.index()].establishes_scroll_container()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -319,9 +319,7 @@ where
|
||||
} else if self.world.is_viewport_defining_body(id) {
|
||||
false
|
||||
} else {
|
||||
self.world.boxes[id.index()]
|
||||
.style
|
||||
.establishes_scroll_container()
|
||||
self.world.boxes[id.index()].establishes_scroll_container()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,6 +254,13 @@ impl LayoutInputControlKind {
|
||||
Self::Week => "form-input-week",
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) const fn has_single_line_text_editor(self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
Self::Email | Self::Password | Self::Search | Self::Telephone | Self::Text | Self::Url
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaced-content family. Pixel resources are deliberately not part of this type.
|
||||
@@ -429,6 +436,14 @@ impl LayoutElementSemantics {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) const fn has_internal_text_control_scroller(&self) -> bool {
|
||||
matches!(
|
||||
self.category,
|
||||
LayoutElementCategory::FormControl(LayoutFormControlKind::Input(kind))
|
||||
if kind.has_single_line_text_editor()
|
||||
)
|
||||
}
|
||||
|
||||
/// Whether `display: contents` has a used value of `display: none`.
|
||||
///
|
||||
/// This is the unusual-elements list from CSS Display's HTML appendix:
|
||||
|
||||
@@ -610,6 +610,14 @@ impl<N> LayoutBox<N> {
|
||||
.is_some_and(LayoutElementSemantics::is_replaced)
|
||||
}
|
||||
|
||||
pub(crate) fn establishes_scroll_container(&self) -> bool {
|
||||
self.style.establishes_scroll_container()
|
||||
|| self
|
||||
.element_semantics
|
||||
.as_ref()
|
||||
.is_some_and(LayoutElementSemantics::has_internal_text_control_scroller)
|
||||
}
|
||||
|
||||
/// Resolve the used ratio at the layout-node boundary, after both authored
|
||||
/// style and natural replaced-element sizing are available.
|
||||
pub(crate) fn resolved_aspect_ratio(&self) -> Option<taffy::ResolvedAspectRatio> {
|
||||
|
||||
+63
@@ -1393,3 +1393,66 @@ fn element_scroll_methods_leave_a_detached_element_at_zero() {
|
||||
r#"{"protoScroll":"function","protoScrollTo":"function","protoScrollBy":"function","first":[0,0],"second":[0,0],"third":[0,0],"fourth":[0,0],"fifth":[0,0],"enumerable":false}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_line_text_input_preserves_programmatic_scroll_across_select() {
|
||||
let mut vm = new_storage_test_vm("https://text-input-scroll.test/");
|
||||
vm.eval(
|
||||
r#"
|
||||
(() => {
|
||||
if (!document.documentElement) {
|
||||
document.appendChild(document.createElement("html"));
|
||||
}
|
||||
if (!document.body) {
|
||||
document.documentElement.appendChild(document.createElement("body"));
|
||||
}
|
||||
const previous = document.createElement("input");
|
||||
previous.value = "0123456789".repeat(100);
|
||||
document.body.append(previous);
|
||||
globalThis.__previousScrollInput = previous;
|
||||
return "installed";
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("text input scroll fixture should initialize");
|
||||
refresh_layout_for_test(&mut vm);
|
||||
vm.eval("__previousScrollInput.scrollLeft")
|
||||
.expect("the previous input should retain the frozen layout");
|
||||
|
||||
vm.eval(
|
||||
r#"
|
||||
(() => {
|
||||
__previousScrollInput.remove();
|
||||
const input = document.createElement("input");
|
||||
input.value = "0123456789".repeat(100);
|
||||
document.body.append(input);
|
||||
globalThis.__scrollInput = input;
|
||||
return "replaced";
|
||||
})()
|
||||
"#,
|
||||
)
|
||||
.expect("the previous text input should be replaced");
|
||||
|
||||
vm.eval("__scrollInput.scrollLeft = 33")
|
||||
.expect("text input should accept a programmatic scroll");
|
||||
refresh_layout_for_test(&mut vm);
|
||||
assert_eq!(
|
||||
vm.eval("__scrollInput.scrollWidth > __scrollInput.clientWidth")
|
||||
.expect("text input overflow should be observable"),
|
||||
"true"
|
||||
);
|
||||
assert_eq!(
|
||||
vm.eval("__scrollInput.scrollLeft")
|
||||
.expect("text input scroll should remain observable"),
|
||||
"33"
|
||||
);
|
||||
|
||||
vm.eval("__scrollInput.select()")
|
||||
.expect("selecting the input contents should succeed");
|
||||
refresh_layout_for_test(&mut vm);
|
||||
assert_eq!(
|
||||
vm.eval("__scrollInput.scrollLeft")
|
||||
.expect("selection should preserve the text input scroll"),
|
||||
"33"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user