Skip to content

[selectors] /idref()/ combinator to follow element references for arbitrary IDREF attributes #10970

@LeaVerou

Description

@LeaVerou

In the past we have been discussing a /for/ combinator to go from a label to the input it references (cannot find the issue now). However, HTML is rife with several IDREF attributes. Here is a small subset:

  • for, in <label> and <output>
  • list in <input>
  • A host of ARIA attributes (e.g. aria-describedby, aria-labelledby, aria-activedescendant, aria-controls, aria-details, aria-flowto, aria-owns etc.)
  • Popovers (popovertarget)
  • Invokers (invoketarget)
  • anchor
  • Plus, web component authors can always define their own, custom IDREF attributes

It seems clear that the path forwards for future combinators is '/' <ident> '/'. But that also opens the path for having functional combinators. What if we define a combinator that takes any attribute as a parameter and treats it as an IDREF?
Then /for/ becomes:

label /idref(for)/ input {
	/* ... */
}

but also things like this are possible:

input.country /idref(list)/ datalist {
	/* ... */
}

Or even:

my-tooltip /idref(for)/ * {
	cursor: help;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions