@@ -785,15 +785,46 @@ Intrinsic Sizes</h3>
785
785
replacing the CSS2 “definition”,
786
786
such as it is.
787
787
788
- When specified on the HTML <{textarea}> element,
789
- the ''width/min-content'' and ''width/max-content'' keywords
790
- are calculated as normal for a non-replaced [=block container=] ,
791
- treating its <l spec=html> [=raw value=] </l> as child [=CSS/text nodes=] .
788
+ <hr>
789
+
790
+ Although the ''width/auto'' size of text input controls
791
+ such as HTML’s <code> <input type=text></code> and <code> <textarea></code> elements
792
+ is typically a fixed size,
793
+ the contents of such elements can be used to determine a content-based intrinsic size,
794
+ as for non-replaced block containers.
795
+ The ''width/min-content'' and ''width/max-content'' keywords of the <a>sizing properties</a>
796
+ thus represent content-based sizes
797
+ for form controls which render their value
798
+ as text contained within their box,
799
+ allowing such controls to size to fit their visible contents
800
+ similarly to regular non-replaced elements.
801
+
802
+ The content in this case is defined to be the input control's values
803
+ (the <l spec=html> [=raw value=] </l> in the case of <{textarea}> ,
804
+ or the <a href="https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-fe-value">value</a> in the case of <{input}> ),
805
+ possibly transformed to a localized display format,
806
+ which is then treated as child <a>text runs</a> of the input control.
807
+ If the input control has <a>placeholder text</a> overlaid,
808
+ then that text is also measured for the purpose of calculating the content-based size--
809
+ whether or not the placeholder text is visible at the moment.
810
+ (Thus the content-based intrinsic size of the input control
811
+ is the larger of the size to fit the placeholder text and the size to fit the value.)
812
+
813
+ Issue: So that this gives sensible results,
814
+ ensure minimum height via UA style sheet
815
+ <code> textarea { min-height: 1lh; }</code> .
816
+
817
+ Issue: <code> <input type=text></code> only ever displays its value on a single line.
818
+ This appears to be accomplished by "magic":
819
+ newlines are removed by a sanitization step on the <code> .value</code> setter,
820
+ and then single-line display is further applied via magic,
821
+ rather than the 'white-space' property in the UA stylesheet.
822
+ Thus, the ''width/min-content'' size should probably automatically treat it as if it had ''white-space: pre'' .
792
823
793
824
Note: See <a href="https://github.com/w3c/csswg-drafts/issues/1771">discussion about this functionality</a> .
794
825
This might be extended to <{iframe}> or other content-containing replaced elements,
795
- but <{textarea}> is the major use-case
796
- and has the least additional complications.
826
+ but text inputs are the major use-case
827
+ and have the least additional complications.
797
828
798
829
<h3 id="intrinsic-contribution">
799
830
Intrinsic Contributions</h3>
0 commit comments