Skip to content
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
33 changes: 33 additions & 0 deletions integration_tests/specs/dom/nodes/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ describe('DOM Element API', () => {
expect(div.hasAttribute('foo')).toBeFalse();
});

it('should work with scroll', () => {
const div = document.createElement('div');

div.style.width = div.style.height = '200px';
div.style.padding = '10px';
div.style.margin = '20px';
div.style.backgroundColor = 'grey';
div.style.overflow = 'scroll';
document.body.appendChild(div);

const scrollDiv = document.createElement('div');
scrollDiv.style.width = '100px';
scrollDiv.style.height = '1000px';
div.appendChild(scrollDiv)

const childDiv = document.createElement('div');
childDiv.style.width = childDiv.style.height = '30px';
childDiv.style.marginTop = '150px';
childDiv.style.backgroundColor = 'yellow';
scrollDiv.appendChild(childDiv);

expect(JSON.parse(JSON.stringify(childDiv.getBoundingClientRect()))).toEqual({
bottom: 210, height: 30, left: 30, right: 60, top: 180, width: 30, x: 30, y: 180
} as any);

div.scrollBy(0, 10);

expect(JSON.parse(JSON.stringify(childDiv.getBoundingClientRect()))).toEqual({
bottom: 200, height: 30, left: 30, right: 60, top: 170, width: 30, x: 30, y: 170
} as any);

});

it('children should only contain elements', () => {
let container = document.createElement('div');
let a = document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion webf/lib/src/css/positioned.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Offset _getPlaceholderToParentOffset(RenderPositionPlaceholder? placeholder, Ren
Offset positionHolderScrollOffset = _getRenderPositionHolderScrollOffset(placeholder, parent) ?? Offset.zero;
// Offset of positioned element should exclude scroll offset to its containing block.
Offset toParentOffset = placeholder.getOffsetToAncestor(Offset.zero, parent, excludeScrollOffset: true);
Offset placeholderOffset = positionHolderScrollOffset + toParentOffset;
Offset placeholderOffset = -positionHolderScrollOffset + toParentOffset;

return placeholderOffset;
}
Expand Down
2 changes: 2 additions & 0 deletions webf/lib/src/rendering/box_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,8 @@ class RenderBoxModel extends RenderBox
final BoxParentData childParentData = child.parentData! as BoxParentData;
Offset offset = childParentData.offset;
if (excludeScrollOffset) {
offset += Offset(scrollLeft, scrollTop);
} else {
offset -= Offset(scrollLeft, scrollTop);
}
transform.translate(offset.dx, offset.dy);
Expand Down