Skip to content
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ _As defined by CSS 4 and / or jQuery._
- [`:scope`](https://developer.mozilla.org/en-US/docs/Web/CSS/:scope):
Selects elements that are part of the scope of the current selector. This
uses the context from the passed options.
- [`:host`](https://developer.mozilla.org/en-US/docs/Web/CSS/:host):
Alias of `:scope`, selecting elements in the current context.

---

Expand Down
2 changes: 2 additions & 0 deletions src/pseudo-selectors/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const textControl =
* Aliases are pseudos that are expressed as selectors.
*/
export const aliases: Record<string, string> = {
host: ":scope",

// Links

"any-link": ":is(a, area, link)[href]",
Expand Down
20 changes: 20 additions & 0 deletions test/pseudo-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ describe("unmatched", () => {
});
});

describe(":host", () => {
it("should match the root element", () => {
const matches = CSSselect.selectAll(":host", dom);

expect(matches).toHaveLength(1);
expect(matches).toStrictEqual([dom[0]]);
});

it("should match context elements", () => {
const p = CSSselect.selectOne("p", dom);

expect(p).not.toBeNull();
expect(
CSSselect.selectAll(":host", dom, {
context: [p as Element],
}),
).toStrictEqual([p]);
});
});

describe(":first-child", () => {
it("should match", () => {
const matches = CSSselect.selectAll(":first-child", dom);
Expand Down