Skip to content

Commit 74ffcfc

Browse files
committed
Chore: Rename containingParent to offsetParent
1 parent 1e0e78f commit 74ffcfc

File tree

10 files changed

+62
-62
lines changed

10 files changed

+62
-62
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: 'Query .containingParent()'
3-
shortTitle: '.containingParent()'
4-
id: 'query-containingparent'
2+
title: 'Query .offsetParent()'
3+
shortTitle: '.offsetParent()'
4+
id: 'query-offsetparent'
55
exampleType: 'component'
66
category: 'Query'
77
subcategory: 'Visibility'
88
tags: ['query', 'containing', 'parent', 'position']
99
description: 'Finds nearest containing parent element'
1010
tip: 'Used for positioning elements relative to their containing block context'
1111
selectedFile: 'page.js'
12-
---
12+
---
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: 'Query .positioningParent()'
3-
shortTitle: '.positioningParent()'
2+
title: 'Query .offsetParent()'
3+
shortTitle: '.offsetParent()'
44
id: 'query-positioningparent'
55
exampleType: 'component'
66
category: 'Query'
77
subcategory: 'Visibility'
8-
tags: ['query', 'positioning', 'parent', 'position', 'fixed', 'absolute']
8+
tags: ['query', 'offset', 'parent', 'position', 'fixed', 'absolute']
99
description: 'Finds the actual positioning context for positioned elements'
10-
tip: 'Unlike containingParent, correctly handles fixed elements and modern CSS positioning contexts'
10+
tip: 'Unlike offsetParent, correctly handles fixed elements and modern CSS positioning contexts'
1111
selectedFile: 'page.js'
12-
---
12+
---

docs/src/examples/query/dom-traversal/query-containingparent/page.css renamed to docs/src/examples/query/dom-traversal/query-offsetparent/page.css

File renamed without changes.

docs/src/examples/query/dom-traversal/query-containingparent/page.html renamed to docs/src/examples/query/dom-traversal/query-offsetparent/page.html

File renamed without changes.

docs/src/examples/query/dom-traversal/query-containingparent/page.js renamed to docs/src/examples/query/dom-traversal/query-offsetparent/page.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $('.toggle-transform').on('click', () => {
1515
const currentTransform = $box.css('transform');
1616
if (currentTransform === 'none') {
1717
$box.css('transform', 'scale(1)');
18-
log('Box transform set to: scale(1) - Now box is the containing parent!');
18+
log('Box transform set to: scale(1) - Now box is the offset parent!');
1919
}
2020
else {
2121
$box.css('transform', 'none');
@@ -33,7 +33,7 @@ $('.toggle-filter').on('click', () => {
3333
const currentFilter = $box.css('filter');
3434
if (currentFilter === 'none') {
3535
$box.css('filter', 'brightness(1)');
36-
log('Box filter set to: brightness(1) - Now box is the containing parent!');
36+
log('Box filter set to: brightness(1) - Now box is the offset parent!');
3737
}
3838
else {
3939
$box.css('filter', 'none');
@@ -46,23 +46,23 @@ $('.toggle-filter').on('click', () => {
4646
}, 10);
4747
});
4848

49-
// Find containing parent
49+
// Find offset parent
5050
$('.find').on('click', () => {
5151
$('.highlight').removeClass('highlight');
5252

53-
const $containingParent = $('.target').containingParent();
54-
$containingParent.addClass('highlight');
53+
const $offsetParent = $('.target').offsetParent();
54+
$offsetParent.addClass('highlight');
5555

56-
if ($containingParent.is('.container')) {
56+
if ($offsetParent.is('.container')) {
5757
log('Containing parent: .container (as expected)');
5858
}
59-
else if ($containingParent.is('.box')) {
59+
else if ($offsetParent.is('.box')) {
6060
log('Containing parent: .box (due to transform/filter!)');
6161
}
6262

6363
// Compare with browser's offsetParent
64-
const $offsetParent = $('.target').containingParent({ calculate: false });
65-
if (!$offsetParent.is($containingParent)) {
64+
const $offsetParent = $('.target').offsetParent({ calculate: false });
65+
if (!$offsetParent.is($offsetParent)) {
6666
$log.append('<br>Note: Browser offsetParent is different!');
6767
}
6868
});

docs/src/pages/api/query/visibility.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,16 +262,16 @@ const $scrollContainer = $content.clippingParent();
262262
### Example
263263
<PlaygroundExample id="query-clippingparent" direction="horizontal"></PlaygroundExample>
264264

265-
## containingParent
265+
## offsetParent
266266

267-
Get the simple containing parent (offsetParent) for each element.
267+
Get the `offsetParent` of an element as reported by the Dom.
268268

269-
> **Simple Access** This is a direct wrapper around the native `offsetParent` property for quick access to basic positioning context.
269+
> **Simple Access** This is a direct wrapper around the native `offsetParent` property this may not always be the positioning parent for fixed position elements.
270270
271271
### Syntax
272272

273273
```javascript
274-
$('selector').containingParent()
274+
$('selector').offsetParent()
275275
```
276276

277277
### Returns
@@ -282,11 +282,11 @@ A new [Query object](/api/query/basic#the-query-object) containing the offset pa
282282

283283
```javascript
284284
// Quick access to offsetParent
285-
const $offsetParent = $('#element').containingParent();
285+
const $offsetParent = $('#element').offsetParent();
286286

287287
// For simple positioning calculations
288288
const $element = $('#positioned-element');
289-
const $parent = $element.containingParent();
289+
const $parent = $element.offsetParent();
290290
console.log('Positioned relative to:', $parent[0]);
291291
```
292292

packages/query/src/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ export class Query {
18161816
return this.chain(parents);
18171817
}
18181818

1819-
containingParent() {
1819+
offsetParent() {
18201820
const parents = this.map(el => el.offsetParent || document.documentElement);
18211821
return this.chain(parents);
18221822
}

packages/query/test/browser/dimensions.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('query', () => {
7878
expect(position).toBeUndefined();
7979
});
8080

81-
it('sets position relative to containingParent by default', async () => {
81+
it('sets position relative to offsetParent by default', async () => {
8282
document.body.innerHTML = `
8383
<div id="container" style="position: relative; width: 500px; height: 500px;">
8484
<div id="child" style="position: absolute; width: 50px; height: 50px;"></div>

packages/query/test/browser/query.test.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ describe('query', () => {
829829
});
830830
});
831831

832-
describe('containingParent', () => {
832+
describe('offsetParent', () => {
833833
beforeEach(() => {
834834
document.body.innerHTML = '';
835835
});
@@ -842,10 +842,10 @@ describe('query', () => {
842842
`;
843843

844844
const $child = $('#child');
845-
const $containingParent = $child.containingParent();
845+
const $offsetParent = $child.offsetParent();
846846

847-
expect($containingParent.length).toBe(1);
848-
expect($containingParent[0]).toBe(document.getElementById('container'));
847+
expect($offsetParent.length).toBe(1);
848+
expect($offsetParent[0]).toBe(document.getElementById('container'));
849849
});
850850

851851
it('should find containing parent with transform', () => {
@@ -856,10 +856,10 @@ describe('query', () => {
856856
`;
857857

858858
const $child = $('#child');
859-
const $containingParent = $child.containingParent();
859+
const $offsetParent = $child.offsetParent();
860860

861-
expect($containingParent.length).toBe(1);
862-
expect($containingParent[0]).toBe(document.getElementById('transformed'));
861+
expect($offsetParent.length).toBe(1);
862+
expect($offsetParent[0]).toBe(document.getElementById('transformed'));
863863
});
864864

865865
it('should find containing parent with filter', () => {
@@ -870,10 +870,10 @@ describe('query', () => {
870870
`;
871871

872872
const $child = $('#child');
873-
const $containingParent = $child.containingParent();
873+
const $offsetParent = $child.offsetParent();
874874

875-
expect($containingParent.length).toBe(1);
876-
expect($containingParent[0]).toBe(document.getElementById('filtered'));
875+
expect($offsetParent.length).toBe(1);
876+
expect($offsetParent[0]).toBe(document.getElementById('filtered'));
877877
});
878878

879879
it('should find containing parent with contain property', () => {
@@ -884,10 +884,10 @@ describe('query', () => {
884884
`;
885885

886886
const $child = $('#child');
887-
const $containingParent = $child.containingParent();
887+
const $offsetParent = $child.offsetParent();
888888

889-
expect($containingParent.length).toBe(1);
890-
expect($containingParent[0]).toBe(document.getElementById('contained'));
889+
expect($offsetParent.length).toBe(1);
890+
expect($offsetParent[0]).toBe(document.getElementById('contained'));
891891
});
892892

893893
it('should find containing parent with will-change', () => {
@@ -898,10 +898,10 @@ describe('query', () => {
898898
`;
899899

900900
const $child = $('#child');
901-
const $containingParent = $child.containingParent();
901+
const $offsetParent = $child.offsetParent();
902902

903-
expect($containingParent.length).toBe(1);
904-
expect($containingParent[0]).toBe(document.getElementById('willchange'));
903+
expect($offsetParent.length).toBe(1);
904+
expect($offsetParent[0]).toBe(document.getElementById('willchange'));
905905
});
906906

907907
it('should return documentElement for fixed elements (null offsetParent fallback)', () => {
@@ -912,11 +912,11 @@ describe('query', () => {
912912
`;
913913

914914
const $fixed = $('#fixed');
915-
const $containingParent = $fixed.containingParent();
915+
const $offsetParent = $fixed.offsetParent();
916916

917917
// Fixed elements have null offsetParent, so should fallback to documentElement
918-
expect($containingParent.length).toBe(1);
919-
expect($containingParent[0]).toBe(document.documentElement);
918+
expect($offsetParent.length).toBe(1);
919+
expect($offsetParent[0]).toBe(document.documentElement);
920920
});
921921

922922
it('should return document.body when no containing parent found', () => {
@@ -929,10 +929,10 @@ describe('query', () => {
929929
`;
930930

931931
const $target = $('#target');
932-
const $containingParent = $target.containingParent();
932+
const $offsetParent = $target.offsetParent();
933933

934-
expect($containingParent.length).toBe(1);
935-
expect($containingParent[0]).toBe(document.body);
934+
expect($offsetParent.length).toBe(1);
935+
expect($offsetParent[0]).toBe(document.body);
936936
});
937937

938938
it('should use browser offsetParent when calculate is false', () => {
@@ -943,10 +943,10 @@ describe('query', () => {
943943
`;
944944

945945
const $child = $('#child');
946-
const $containingParent = $child.containingParent({ calculate: false });
946+
const $offsetParent = $child.offsetParent({ calculate: false });
947947

948-
expect($containingParent.length).toBe(1);
949-
expect($containingParent[0]).toBe(document.getElementById('child').offsetParent);
948+
expect($offsetParent.length).toBe(1);
949+
expect($offsetParent[0]).toBe(document.getElementById('child').offsetParent);
950950
});
951951

952952
it('should handle multiple elements', () => {
@@ -960,18 +960,18 @@ describe('query', () => {
960960
`;
961961

962962
const $items = $('.item');
963-
const $containingParents = $items.containingParent();
963+
const $offsetParents = $items.offsetParent();
964964

965-
expect($containingParents.length).toBe(2);
966-
expect($containingParents[0]).toBe(document.getElementById('container1'));
967-
expect($containingParents[1]).toBe(document.getElementById('container2'));
965+
expect($offsetParents.length).toBe(2);
966+
expect($offsetParents[0]).toBe(document.getElementById('container1'));
967+
expect($offsetParents[1]).toBe(document.getElementById('container2'));
968968
});
969969

970970
it('should handle empty selection', () => {
971971
const $empty = $('.nonexistent');
972-
const $containingParent = $empty.containingParent();
972+
const $offsetParent = $empty.offsetParent();
973973

974-
expect($containingParent.length).toBe(0);
974+
expect($offsetParent.length).toBe(0);
975975
});
976976

977977
it('should find nearest containing parent in nested contexts', () => {
@@ -986,11 +986,11 @@ describe('query', () => {
986986
`;
987987

988988
const $target = $('#target');
989-
const $containingParent = $target.containingParent();
989+
const $offsetParent = $target.offsetParent();
990990

991991
// Should find the immediate containing parent (inner), not the outer one
992-
expect($containingParent.length).toBe(1);
993-
expect($containingParent[0]).toBe(document.getElementById('inner'));
992+
expect($offsetParent.length).toBe(1);
993+
expect($offsetParent[0]).toBe(document.getElementById('inner'));
994994
});
995995
});
996996

packages/query/test/dom/dimensions.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe('Query Dimensions', () => {
139139
});
140140
});
141141

142-
describe('containingParent()', () => {
142+
describe('offsetParent()', () => {
143143
beforeEach(() => {
144144
document.body.innerHTML = '';
145145
});
@@ -151,7 +151,7 @@ describe('Query Dimensions', () => {
151151
</div>
152152
`;
153153

154-
const result = $('#child').containingParent();
154+
const result = $('#child').offsetParent();
155155
expect(result).toBeInstanceOf(Query);
156156
});
157157
});

0 commit comments

Comments
 (0)