Skip to content

Commit d62b661

Browse files
authored
docs: rename proximity selectors to position selectors (#4975)
1 parent cb6e4a6 commit d62b661

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

docs/src/selectors.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Playwright supports various selector engines:
2020
- [`:visible`](#css-extension-visible) pseudo-class
2121
- [`:text`](#css-extension-text) pseudo-class
2222
- [`:has`](#css-extension-has) and [`:is`](#css-extension-is) pseudo-classes
23-
- [Proximity selectors](#css-extension-proximity), for example `button:right-of(article)`
23+
- [Position selectors](#css-extension-position), for example `button:right-of(article)`
2424
* [XPath] selectors, for example `xpath=//html/body/div`
2525
* [id selectors][id], for example `id=sign-in`
2626
* [Custom selector engines](./extensibility.md)
@@ -217,7 +217,7 @@ Consider a page with two buttons, first invisible and second visible.
217217

218218
```js
219219
await page.click('button:visible');
220-
```
220+
```
221221

222222
Use `:visible` with caution, because it has two major drawbacks:
223223
* When elements change their visibility dynamically, `:visible` will give upredictable results based on the timing.
@@ -264,13 +264,13 @@ await page.click('button:is(:text("Log in"), :text("Sign in"))');
264264
await page.click(':light(.article > .header)');
265265
```
266266

267-
### CSS extension: proximity
267+
### CSS extension: position
268268

269-
Playwright provides a few proximity selectors based on the page layout. These can be combined with regular CSS for better results, for example `input:right-of(:text("Password"))` matches an input field that is to the right of text "Password".
269+
Playwright provides position selectors based on the page layout. These can be combined with regular CSS for better results, for example `input:right-of(:text("Password"))` matches an input field that is to the right of text "Password".
270270

271-
Note that proximity selectors depend on the page layout and may produce unexpected results. For example, a different element could be matched when layout changes by one pixel.
271+
Note that position selectors depend on the page layout and may produce unexpected results. For example, a different element could be matched when layout changes by one pixel.
272272

273-
Proximity selectors use [bounding client rect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) to compute distance and relative position of the elements.
273+
Position selectors use [bounding client rect](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) to compute distance and relative position of the elements.
274274
* `:right-of(inner > selector)` - Matches elements that are to the right of any element matching the inner selector.
275275
* `:left-of(inner > selector)` - Matches elements that are to the left of any element matching the inner selector.
276276
* `:above(inner > selector)` - Matches elements that are above any of the elements matching the inner selector.

src/server/injected/selectorEvaluator.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export class SelectorEvaluatorImpl implements SelectorEvaluator {
5858
this._engines.set('text', textEngine);
5959
this._engines.set('text-is', textIsEngine);
6060
this._engines.set('text-matches', textMatchesEngine);
61-
this._engines.set('right-of', createProximityEngine('right-of', boxRightOf));
62-
this._engines.set('left-of', createProximityEngine('left-of', boxLeftOf));
63-
this._engines.set('above', createProximityEngine('above', boxAbove));
64-
this._engines.set('below', createProximityEngine('below', boxBelow));
65-
this._engines.set('near', createProximityEngine('near', boxNear));
61+
this._engines.set('right-of', createPositionEngine('right-of', boxRightOf));
62+
this._engines.set('left-of', createPositionEngine('left-of', boxLeftOf));
63+
this._engines.set('above', createPositionEngine('above', boxAbove));
64+
this._engines.set('below', createPositionEngine('below', boxBelow));
65+
this._engines.set('near', createPositionEngine('near', boxNear));
6666
}
6767

6868
// This is the only function we should use for querying, because it does
@@ -489,7 +489,7 @@ function boxNear(box1: DOMRect, box2: DOMRect): number | undefined {
489489
return score > kThreshold ? undefined : score;
490490
}
491491

492-
function createProximityEngine(name: string, scorer: (box1: DOMRect, box2: DOMRect) => number | undefined): SelectorEngine {
492+
function createPositionEngine(name: string, scorer: (box1: DOMRect, box2: DOMRect) => number | undefined): SelectorEngine {
493493
return {
494494
matches(element: Element, args: (string | number | Selector)[], context: QueryContext, evaluator: SelectorEvaluator): boolean {
495495
if (!args.length)

test/selectors-misc.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ it('should work with :visible', async ({page}) => {
4747
expect(await page.$eval('div:visible', div => div.id)).toBe('target2');
4848
});
4949

50-
it('should work with proximity selectors', async ({page}) => {
50+
it('should work with position selectors', async ({page}) => {
5151
/*
5252
5353
+--+ +--+

0 commit comments

Comments
 (0)