Skip to content

Commit 2b42b64

Browse files
committed
[selectors-4] Define :empty to ignore whitespace. Define :blank to apply to empty inputs. #1967 #1283
1 parent 6a0270b commit 2b42b64

File tree

1 file changed

+60
-42
lines changed

1 file changed

+60
-42
lines changed

selectors-4/Overview.bs

Lines changed: 60 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ Selectors Overview</h2>
397397
<td>3
398398
<tr>
399399
<td><code>E:empty</code>
400-
<td>an E element that has no children (not even text nodes)
400+
<td>an E element that has no children (neither elements nor text)
401401
<td>[[#structural-pseudos]]
402402
<td>3
403403
<tr>
@@ -2580,6 +2580,26 @@ The Indeterminate-value Pseudo-class: '':indeterminate''</h4>
25802580
<h3 id='ui-validity'>
25812581
Input Value-checking</h3>
25822582

2583+
<h4 id="blank">
2584+
The Empty-Value Pseudo-class: '':blank''</h4>
2585+
2586+
The <dfn id="blank-pseudo">:blank</dfn> pseudo-class
2587+
applies to user-input elements whose input value is empty
2588+
(consists of the empty string or otherwise null input).
2589+
2590+
<div class="example">
2591+
Examples of '':blank'' user-input elements would be
2592+
a <{textarea}> element whose contents are empty,
2593+
or an <{input}> field whose value is empty.
2594+
Note that the value under consideration here is the value
2595+
that would be submitted
2596+
(see <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#a-form-control's-value">A form control’s value</a> in [[HTML]]),
2597+
which in HTML does not necessarily correspond to the value
2598+
of the element’s <{input/value}> attribute.
2599+
</div>
2600+
2601+
Note: This selector is at-risk.
2602+
25832603
<h4 id="validity-pseudos">
25842604
The Validity Pseudo-classes: '':valid'' and '':invalid''</h4>
25852605

@@ -2697,7 +2717,9 @@ Tree-Structural pseudo-classes</h2>
26972717
<h3 id="the-empty-pseudo">
26982718
'':empty'' pseudo-class</h3>
26992719

2700-
The <dfn id='empty-pseudo'>:empty</dfn> pseudo-class represents an element that has no children at all.
2720+
The <dfn id='empty-pseudo'>:empty</dfn> pseudo-class represents
2721+
an element that has no children
2722+
except, optionally, <a>document white space characters</a>.
27012723
In terms of the document tree,
27022724
only element nodes and content nodes
27032725
(such as [[DOM]] text nodes, and entity references)
@@ -2707,48 +2729,37 @@ Tree-Structural pseudo-classes</h2>
27072729

27082730
<div class="example">
27092731
Examples:
2710-
''p:empty'' is a valid representation of the following fragment:
2711-
2712-
<pre>&lt;p>&lt;/p></pre>
2713-
2714-
''foo:empty'' is not a valid representation for the
2715-
following fragments:
2716-
2717-
<pre>&lt;foo>bar&lt;/foo></pre>
2718-
2719-
<pre>&lt;foo>&lt;bar>bla&lt;/bar>&lt;/foo></pre>
2720-
2721-
<pre>&lt;foo>this is not &lt;bar>:empty&lt;/bar>&lt;/foo></pre>
2722-
</div>
2723-
2724-
Issue: The WG is considering whether to allow elements containing only white space to match this selector.
2725-
The advantage would be that--
2726-
as white space is largely collapsible in HTML and is therefore used for source code formatting, and especially because elements with omitted end tags are likely to absorb such white space into their DOM text contents--
2727-
many elements which authors perceive of as empty would be selected by this selector, as they expect.
2728-
The disadvantages are a potential conflict with Web-compat if there exist pages that depend on this selector excluding white space;
2729-
and that one might consider uncollapsed white space to be significant content, but the selector cannot change its behavior based on the 'white-space' property.
2730-
See <a href="https://github.com/w3c/csswg-drafts/issues/1967">discussion</a>.
2731-
2732-
2733-
<h3 id='the-blank-pseudo'>
2734-
'':blank'' pseudo-class</h3>
2735-
2736-
The <dfn id='blank-pseudo'>:blank</dfn> pseudo-class is like the '':empty'' pseudo-class,
2737-
except that it additionally matches elements that only contain
2738-
<a href="https://www.w3.org/TR/css3-text/#white-space-rules">code points affected by whitespace processing</a>. [[!CSS3TEXT]]
2732+
''p:empty'' is a valid representation of the <{p}> elements
2733+
in the following HTML fragment:
2734+
2735+
<pre class="html">
2736+
&lt;p>&lt;/p>
2737+
&lt;p>
2738+
&lt;p> &lt;/p>
2739+
&lt;p><!-- comment -->&lt;/p>
2740+
</pre>
27392741

2740-
<div class='example'>
2741-
For example, the following element matches '':blank'',
2742-
but not '':empty'',
2743-
because it contains at least one linebreak, and possibly other whitespace:
2742+
''div:empty'' is not a valid representation of the <code>&lt;div></code> elements
2743+
in the following fragment:
27442744

2745-
<pre>&lt;p><br>&lt;/p></pre>
2745+
<pre class="html">
2746+
&lt;div>text&lt;/div>
2747+
&lt;div>&lt;p>&lt;/p>&lt;/div>
2748+
&lt;div>&amp;nbsp;&lt;/div>
2749+
&lt;div>&lt;p>bla&lt;/p>&lt;/div>
2750+
&lt;div>this is not &lt;p>:empty&lt;/p>&lt;/div>
2751+
</pre>
27462752
</div>
27472753

2748-
Issue: The WG is considering whether to rename this or file its definition under the existing '':empty'' pseudo-class.
2749-
See <a href="https://github.com/w3c/csswg-drafts/issues/1967">discussion</a>.
2750-
There's also a <a href="https://github.com/w3c/csswg-drafts/issues/1283">related issue</a> on a selector for empty input fields which might legitimately steal this name.
2751-
2754+
Note: In Level 2 and Level 3 of Selectors,
2755+
'':empty'' did not match elements that contained only white space.
2756+
This was changed so that that--
2757+
given white space is largely collapsible in HTML
2758+
and is therefore used for source code formatting,
2759+
and especially because elements with omitted end tags
2760+
are likely to absorb such white space into their DOM text contents--
2761+
elements which authors perceive of as empty
2762+
can be selected by this selector, as they expect.
27522763

27532764
<h3 id='child-index'>
27542765
Child-indexed Pseudo-classes</h3>
@@ -3897,6 +3908,13 @@ Appendix B: Obsolete but Required Parsing Quirks for Web Compat</h2>
38973908
<h2 id="changes">
38983909
Changes</h2>
38993910

3911+
Significant changes since the <a href="https://www.w3.org/TR/2018/WD-selectors-4-20180202/">2 February 2018 Working Draft</a>:
3912+
3913+
<ul>
3914+
<li>Removed '':blank'' and defined '':empty'' to ignored white-space&ndash;only nodes.
3915+
(<a href="https://github.com/w3c/csswg-drafts/issues/1967">Issue 1967</a>)
3916+
</ul>
3917+
39003918
Significant changes since the <a href="https://www.w3.org/TR/2013/WD-selectors4-20130502/">2 May 2013 Working Draft</a> include:
39013919

39023920
<ul>
@@ -3906,7 +3924,7 @@ Changes</h2>
39063924
<li>Replaced the '':nth-match()'' and '':nth-last-match()'' selectors
39073925
with '':nth-child(&hellip; of <var>selector</var>)'' and '':nth-last-child(&hellip; of <var>selector</var>)''.
39083926
<li>Changed the <css>:active-drop-target</css>, <css>:valid-drop-target</css>, <css>:invalid-drop-target</css> with '':drop()''.
3909-
<li>Sketched out an empty-or-whitespace-only selector for discussion ('':blank'').
3927+
<li>Sketched out an empty-or-whitespace-only selector for discussion
39103928
(See <a href="https://github.com/w3c/csswg-drafts/issues/1967">open issue</a>.)
39113929
<li>Renamed '':user-error'' to '':user-invalid''.
39123930
(See <a href="https://www.w3.org/mid/CADhPm3v+WfeGQfBwwx8QBuiOjn2k38V_DcKW17Cm81VgZb1nbQ@mail.gmail.com">Discussion</a>)
@@ -3948,7 +3966,7 @@ Changes</h2>
39483966
Significant changes since the <a href="https://www.w3.org/TR/2012/WD-selectors4-20120823/">23 August 2012 Working Draft</a> include:
39493967

39503968
<ul>
3951-
<li>Added '':blank'' and '':placeholder-shown'' pseudo-classes.
3969+
<li>Added '':placeholder-shown'' pseudo-classes.
39523970
<li>Released some restrictions on '':matches()'' and '':not()''.
39533971
<li>Defined fast and complete Selectors profiles (now called <a>live</a> and <a>snapshot</a>).
39543972
<li>Improved definition of <a>specificity</a> to better handle <a>:matches()</a>.

0 commit comments

Comments
 (0)