Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positioning to multiline elements #3004

Merged
merged 34 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,3 +898,7 @@ export function getAssociatedElement (el: HTMLElement): HTMLElement | null {

return el.control || el.htmlFor && nativeMethods.getElementById.call(doc, el.htmlFor);
}

export function getClientRectangle (el: HTMLElement): DOMRect {
return el.getClientRects()[0] ?? el.getBoundingClientRect();
}
2 changes: 1 addition & 1 deletion src/client/utils/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function getElementRectangle (el) {
rectangle = getSelectChildRectangle(el);
else {
const elementOffset = getOffsetPosition(el);
const relativeRectangle = domUtils.isSVGElementOrChild(el) ? getSvgElementRelativeRectangle(el) : el.getBoundingClientRect();
const relativeRectangle = domUtils.isSVGElementOrChild(el) ? getSvgElementRelativeRectangle(el) : domUtils.getClientRectangle(el);

rectangle = {
height: relativeRectangle.height,
Expand Down
4 changes: 2 additions & 2 deletions src/client/utils/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export function getOffset (el) {
if (!el || domUtils.isWindow(el) || domUtils.isDocument(el))
return null;

let clientRect = el.getBoundingClientRect();
let clientRect = domUtils.getClientRectangle(el);

// NOTE: A detached node or documentElement.
const doc = el.ownerDocument;
Expand All @@ -338,7 +338,7 @@ export function getOffset (el) {
const scrollTop = win.pageYOffset || docElement.scrollTop || doc.body.scrollTop;
const scrollLeft = win.pageXOffset || docElement.scrollLeft || doc.body.scrollLeft;

clientRect = el.getBoundingClientRect();
clientRect = domUtils.getClientRectangle(el);

return {
top: clientRect.top + scrollTop - clientTop,
Expand Down
47 changes: 43 additions & 4 deletions test/client/fixtures/sandbox/node/classes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ var browserUtils = hammerhead.utils.browser;
var nativeMethods = hammerhead.nativeMethods;

var isFirefox = browserUtils.isFirefox;
var isChrome = browserUtils.isChrome;

function testInvalidWebSocketUrl (url) {
asyncTest('WebSocket constructor with invalid URL ' + url + ' throws async error', function () {
expect(1);

var socket;

try {
socket = new WebSocket(url);
}
catch (e) {
ok(true, 'WebSocket connection failed as expected for ' + url + '.');
start();
}

if (socket) {
socket.onerror = function () {
ok(true, 'WebSocket connection failed as expected for ' + url + '.');
start();
};

socket.onopen = function () {
ok(false, 'WebSocket connection unexpectedly succeeded for ' + url + '.');
start();
};
}
});
}

if (window.PerformanceNavigationTiming) {
test('PerformanceNavigationTiming.name', function () {
Expand Down Expand Up @@ -542,11 +571,11 @@ if (window.WebSocket) {
new WebSocket();
});

throws(function () {
new WebSocket('');
});
if (!(isFirefox || isChrome)) {
throws(function () {
new WebSocket('');
});

if (!isFirefox) {
throws(function () {
new WebSocket('/path');
});
Expand All @@ -561,6 +590,16 @@ if (window.WebSocket) {
}
});
/* eslint-enable no-new */

const invalidUrls = [
{ url: '' },
{ url: '/path' },
{ url: '//example.com' },
{ url: 'http://example.com' },
];

for (let i = 0; i < invalidUrls.length; i++)
testInvalidWebSocketUrl(invalidUrls[i].url);
}

module('regression');
Expand Down
Loading