Skip to content

Commit

Permalink
Positioning to multiline elements (#3004)
Browse files Browse the repository at this point in the history
* testing

* fix tests

* fix pr comments

* fix pr comments

* isolate windows 10 chrome cloud tests

* isolate windows 10 chrome cloud tests

* test skipped for chrome

* test skipped for chrome

* fixing tests

* testing

* restore

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

* testing

---------

Co-authored-by: Bayheck <[email protected]>
  • Loading branch information
Bayheck and Bayheck authored May 29, 2024
1 parent 6fae96f commit fe16afb
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 7 deletions.
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

0 comments on commit fe16afb

Please sign in to comment.