-
Notifications
You must be signed in to change notification settings - Fork 753
Description
The ::placeholder and :placeholder-shown selectors apply to elements with explicit placeholder attributes, like <input> and <textarea>. Should they also match <select> elements with a “placeholder label option”?
HTML Standard / Form Elements / §4.10.7 The select element / #placeholder-label-option:
If a
selectelement has arequiredattribute specified, does not have amultipleattribute specified, and has a display size of 1; and if the value of the firstoptionelement in theselectelement's list of options (if any) is the empty string, and thatoptionelement's parent node is theselectelement (and not anoptgroupelement), then that option is theselectelement's placeholder label option.
My intuition suggests that the following would be true:
:placeholder-shownmatches a<select>where its currently selected<option>is a placeholder label option::placeholdermatches said<option>(or a pseudo-element inside it)
It’s sort of possible to emulate this today:
/* Rough, not-100% alternative to select:placeholder-shown */
select:required:invalid {
/* … */
}
/* Fairly close but v. ugly equivalent to select::placeholder */
select:required:not([multiple]):matches(:not([size]), [size="1"]) >
option:first-child:matches([value=""], :empty:not([value]) {
/* … */
}But the constraints outlined in the HTML spec aren’t perfectly expressible with other selectors*, so having the placeholder-related selectors apply to this case would be useful.
* In no particular order, and I’m sure not a complete list:
-
Weird values in the
sizeattribute (zero, negative numbers, floats, non-numeric characters) can still cause the display size to become 1 -
A
:required<select>can be:invalidfor other reasons, such assetCustomValidity() -
There may be other elements in front of the first direct-child
<option>, like<script>and<template>