mirror of
https://github.com/servo/servo.git
synced 2025-09-30 08:39:16 +01:00
script: Do not call "scroll into view" when handling element clicks (#39326)
Previously, when we click any element, it would trigger "scroll into view". What's worse, for an anchor `<a>`, clicking it would "scroll into view" instead of navigating to the url until you retry the click. The reason is that we built `scrollIntoView` into the focus transaction system with default option. However, the default `preventScroll` for `FocusOption` is false according to spec, which triggers "scroll into view" by default with focus triggered by interaction. This PR 1. Adds spec document for those which really expects "scroll into view", i.e. `<form>` when validating data. 2. Make sure when we begin focus transaction, we prevent "scroll into view". 3. `Focus` method of element/document stays unchanged, which by default scroll into view if no parameter provided according to spec. Testing: Manually tested on `servo.org` and other websites, and examples with `<form>` still correctly scroll into view when validation fails. Fixes: #38616 --------- Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
d96b147bab
commit
8c50c44942
3 changed files with 27 additions and 10 deletions
|
@ -1161,7 +1161,9 @@ impl Document {
|
|||
*self.focus_transaction.borrow_mut() = Some(FocusTransaction {
|
||||
element: self.focused.get().as_deref().map(Dom::from_ref),
|
||||
has_focus: self.has_focus.get(),
|
||||
focus_options: FocusOptions::default(),
|
||||
focus_options: FocusOptions {
|
||||
preventScroll: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1199,7 +1201,14 @@ impl Document {
|
|||
focus_initiator: FocusInitiator,
|
||||
can_gc: CanGc,
|
||||
) {
|
||||
self.request_focus_with_options(elem, focus_initiator, FocusOptions::default(), can_gc);
|
||||
self.request_focus_with_options(
|
||||
elem,
|
||||
focus_initiator,
|
||||
FocusOptions {
|
||||
preventScroll: true,
|
||||
},
|
||||
can_gc,
|
||||
);
|
||||
}
|
||||
|
||||
/// Request that the given element receive focus once the current
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue