mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-22 04:34:44 +00:00
Merge pull request #1588 from egrs/click-to-focus
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test using v8 in debug mode (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
e2e-integration-test / zig build release (push) Has been cancelled
e2e-integration-test / demo-integration-scripts (push) Has been cancelled
click on focusable elements calls focus() with events
This commit is contained in:
@@ -3045,21 +3045,25 @@ pub fn handleClick(self: *Page, target: *Node) !void {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try element.focus(self);
|
||||||
try self.scheduleNavigation(href, .{
|
try self.scheduleNavigation(href, .{
|
||||||
.reason = .script,
|
.reason = .script,
|
||||||
.kind = .{ .push = null },
|
.kind = .{ .push = null },
|
||||||
}, .anchor);
|
}, .anchor);
|
||||||
},
|
},
|
||||||
.input => |input| switch (input._input_type) {
|
.input => |input| {
|
||||||
.submit => return self.submitForm(element, input.getForm(self), .{}),
|
try element.focus(self);
|
||||||
else => self.window._document._active_element = element,
|
if (input._input_type == .submit) {
|
||||||
|
return self.submitForm(element, input.getForm(self), .{});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.button => |button| {
|
.button => |button| {
|
||||||
|
try element.focus(self);
|
||||||
if (std.mem.eql(u8, button.getType(), "submit")) {
|
if (std.mem.eql(u8, button.getType(), "submit")) {
|
||||||
return self.submitForm(element, button.getForm(self), .{});
|
return self.submitForm(element, button.getForm(self), .{});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.select, .textarea => self.window._document._active_element = element,
|
.select, .textarea => try element.focus(self),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,3 +88,46 @@
|
|||||||
testing.expectEqual(focused, document.activeElement);
|
testing.expectEqual(focused, document.activeElement);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<script id="click_focuses_element">
|
||||||
|
{
|
||||||
|
const input1 = $('#input1');
|
||||||
|
const input2 = $('#input2');
|
||||||
|
|
||||||
|
if (document.activeElement) {
|
||||||
|
document.activeElement.blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
let focusCount = 0;
|
||||||
|
let blurCount = 0;
|
||||||
|
|
||||||
|
input1.addEventListener('focus', () => focusCount++);
|
||||||
|
input1.addEventListener('blur', () => blurCount++);
|
||||||
|
input2.addEventListener('focus', () => focusCount++);
|
||||||
|
|
||||||
|
// Click input1 — should focus it and fire focus event
|
||||||
|
input1.click();
|
||||||
|
testing.expectEqual(input1, document.activeElement);
|
||||||
|
testing.expectEqual(1, focusCount);
|
||||||
|
testing.expectEqual(0, blurCount);
|
||||||
|
|
||||||
|
// Click input2 — should move focus, fire blur on input1 and focus on input2
|
||||||
|
input2.click();
|
||||||
|
testing.expectEqual(input2, document.activeElement);
|
||||||
|
testing.expectEqual(2, focusCount);
|
||||||
|
testing.expectEqual(1, blurCount);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script id="click_focuses_button">
|
||||||
|
{
|
||||||
|
const btn = $('#btn1');
|
||||||
|
|
||||||
|
if (document.activeElement) {
|
||||||
|
document.activeElement.blur();
|
||||||
|
}
|
||||||
|
|
||||||
|
btn.click();
|
||||||
|
testing.expectEqual(btn, document.activeElement);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user