You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Experimental feature** - *This will probably be turned on by default and the option will be removed, after I thoroughly evaluate that it produces valid selectors in all use cases.*
333
+
334
+
If set to `true` and the [`root` option](#root-element) is provided, the fallback selectors will be created relative to the `root` element using the `:scope` pseudo-class.
335
+
336
+
For example, if you have the following HTML structure:
337
+
338
+
```html
339
+
<html>
340
+
<body>
341
+
<div>
342
+
<div><!-- haystackElement -->
343
+
<div>
344
+
<div><!-- needleElement --></div>
345
+
</div>
346
+
</div>
347
+
</div>
348
+
</body>
349
+
</html>
350
+
```
351
+
352
+
If you generate the selector **without** the `useScope` option:
... where the selectors correspond with these elements:
368
+
369
+
```
370
+
:root -><html>
371
+
>:nth-child(1) -><body>
372
+
>:nth-child(1) -><div>
373
+
>:nth-child(1) -><div><!-- haystackElement -->
374
+
>:nth-child(1) -><div>
375
+
>:nth-child(1) -><div><!-- needleElement -->
376
+
```
377
+
378
+
But if you generate the selector **with** the `useScope` option:
379
+
380
+
```javascript
381
+
getCssSelector(needleElement, {
382
+
root: haystackElement,
383
+
useScope:true,
384
+
});
385
+
```
386
+
387
+
...it will produce this fallback selector:
388
+
389
+
```:scope >:nth-child(1) >:nth-child(1)```
390
+
391
+
... where the selectors correspond with these elements:
392
+
393
+
```
394
+
:scope -><div><!-- haystackElement -->
395
+
>:nth-child(1) -><div>
396
+
>:nth-child(1) -><div><!-- needleElement -->
397
+
```
398
+
329
399
## Bug reports, feature requests and contact
330
400
331
401
If you found any bugs, if you have feature requests or any questions, please, either [file an issue on GitHub][1] or send me an e-mail at [riki@fczbkk.com][2]
Copy file name to clipboardExpand all lines: src/types.ts
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -73,6 +73,8 @@ export type CssSelectorGeneratorOptionsInput = Partial<{
73
73
maxCombinations: number;
74
74
// Maximum number of selector candidates to be tested for each element. This is handy for performance reasons, e.g. when elements can produce large number of combinations of various types of selectors.
75
75
maxCandidates: number;
76
+
// Experimental. If set to `true` and the "root" option is set, the fallback selectors will use ":scope" pseudo-class to make the selectors shorter and simpler.
0 commit comments