Skip to content

[selectors] Modifier for attribute selectors to split values into words #14371

Description

@SebastianZ

In #10001 (comment) @paceaux suggested to introduce a new modifier w that changes the value matching to take word boundaries into account.

Taking the example from that comment, the selector

[class^="foo" w]

allows to match all of

<div class="foo-bar">
<div class="foo bar">
<div class="bar foo">
<div class="bar foo--baz">

Though it is not restricted to word prefixes. It could be used in any attribute selector.

So here are some more examples:

Matching suffixes is done via

[data-values$="bar" w]

matches

<div data-values="foo-bar">
<div data-values="foo-bar baz">
<div data-values="foo bar baz">
<div data-values="foobar baz">

Exact word matching (equivalent to [attr~=value]):

[data-values="foo" w]

matches

<div data-values="foo">
<div data-values="bar foo">
<div data-values="foo bar">
<div data-values="bar foo baz">

but not

<div data-values="foobar">
<div data-values="foo-bar">
<div data-values="barfoo">
<div data-values="bar-foo">

Applied to |=:

[data-values|="foo" w]

matches

<div data-values="foo">
<div data-values="foo-bar">
<div data-values="baz foo">
<div data-values="baz foo-bar">
<div data-values="bar foo baz">
<div data-values="bar foo-baz biz">

but not

<div data-values="foobar">
<div data-values="barfoo">

This can be seen as a counter-proposal to #14289 and covers more use cases than the ones outlined there.

Sebastian

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