Re: [whatwg/dom] Element.matches and :scope (Issue #1081)

christophehenry left a comment (whatwg/dom#1081)

Ah yes, sorry. Well, I'm not aware of any SO questions but a use-case I have right now is [Stimulus outlets](https://stimulus.hotwired.dev/reference/outlets). Stimulus is a library where most of the API is HTML data attributes. It offers the possibility to write components and bind other Stimulus components on the page through what they call outlets. The current API lets you filter down which specific outlets you want to bind by using a CSS selector matching the node on which the controller is bound (please refer to the documentation I linked earlier if my explanation is not clear).

However it does so [by using `element.matches` on the controller's bound nodes](https://github.com/hotwired/stimulus/blob/main/src/core/outlet_set.ts#L69). This makes it impossible to do composition with Stimulus using controller, i.e component A has one or more children controllers B. This would be useful for complex form components. For instance dorpdowns, or rich `<select>` featuring a searchbar.

Note that Stimulus offers an alternative API that allows to circumvent this problem, but this API is more verbose and less convenient.

I admit this may look like a fringe use-case but I believe that other usages may emerge from solving this.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1081#issuecomment-4610174210
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1081/4610174210@github.com>

Received on Wednesday, 3 June 2026 07:47:33 UTC