13
13
* @property string $className Gets and sets the value of the class attribute
14
14
* @property-read TokenList $classList Returns a live TokenList collection of
15
15
* the class attributes of the element
16
- * @property bool $checked Indicates whether the element is checked or not
17
- * @property bool $selected Indicates whether the element is selected or not
18
16
* @property string $value Gets or sets the value of the element according to
19
17
* its element type
20
18
* @property string $id Gets or sets the value of the id attribute
26
24
* @property string $innerText
27
25
* @property-read StringMap $dataset
28
26
*
27
+ * @property bool allowfullscreen
28
+ * @property bool allowpaymentrequest
29
+ * @property bool async
30
+ * @property bool autocapitalize
31
+ * @property bool autocomplete
32
+ * @property bool autofocus
33
+ * @property bool autoplay
34
+ * @property bool checked Indicates whether the element is checked or not
35
+ * @property bool contentEditable
36
+ * @property bool controls
37
+ * @property bool default
38
+ * @property bool defer
39
+ * @property bool disabled
40
+ * @property bool formnovalidate
41
+ * @property bool hidden
42
+ * @property bool ismap
43
+ * @property bool loop
44
+ * @property bool multiple
45
+ * @property bool muted
46
+ * @property bool novalidate
47
+ * @property bool open
48
+ * @property bool optimum
49
+ * @property bool preload
50
+ * @property bool readonly
51
+ * @property bool required
52
+ * @property bool reversed
53
+ * @property bool selected Indicates whether the element is selected or not
54
+ * @property bool typemustmatch
55
+ *
29
56
* @property string accept
30
57
* @property string acceptCharset
31
58
* @property string accessKey
32
59
* @property string action
33
- * @property bool async
34
- * @property bool autofocus
35
- * @property bool autoplay
36
60
* @property string alt
37
- * @property bool autocapitalize
38
- * @property bool autocomplete
39
61
* @property string charset
40
62
* @property string cite
41
63
* @property string cols
42
- * @property bool contentEditable
43
- * @property bool controls
44
64
* @property string data
45
65
* @property string dateTime
46
- * @property bool defer
47
- * @property bool disabled
48
66
* @property string dir
49
- * @property bool draggable
50
67
* @property string download
51
68
* @property string encoding
52
69
* @property string enctype
58
75
* @property string kind
59
76
* @property string label
60
77
* @property string lang
61
- * @property bool loop
62
78
* @property string low
63
79
* @property string min
64
80
* @property string max
65
81
* @property string maxLength
66
82
* @property string mediaGroup
67
- * @property bool multiple
68
- * @property bool muted
69
83
* @property string name
70
- * @property bool optimum
71
84
* @property string pattern
72
85
* @property string placeholder
73
86
* @property string poster
74
- * @property bool preload
75
87
* @property string readOnly
76
88
* @property string rel
77
- * @property bool reversed
78
- * @property bool required
79
89
* @property string rows
80
90
* @property string start
81
91
* @property string step
@@ -99,6 +109,31 @@ class Element extends DOMElement {
99
109
use LiveProperty, NonDocumentTypeChildNode, ChildNode, ParentNode;
100
110
101
111
const VALUE_ELEMENTS = ["BUTTON " , "INPUT " , "METER " , "OPTION " , "PROGRESS " , "PARAM " ];
112
+ const BOOLEAN_ATTRIBUTES = [
113
+ "allowfullscreen " ,
114
+ "allowpaymentrequest " ,
115
+ "async " ,
116
+ "autofocus " ,
117
+ "autoplay " ,
118
+ "checked " ,
119
+ "controls " ,
120
+ "default " ,
121
+ "defer " ,
122
+ "disabled " ,
123
+ "formnovalidate " ,
124
+ "hidden " ,
125
+ "ismap " ,
126
+ "loop " ,
127
+ "multiple " ,
128
+ "muted " ,
129
+ "novalidate " ,
130
+ "open " ,
131
+ "readonly " ,
132
+ "required " ,
133
+ "reversed " ,
134
+ "selected " ,
135
+ "typemustmatch " ,
136
+ ];
102
137
103
138
/** @var TokenList */
104
139
protected $ liveProperty_classList ;
@@ -381,6 +416,34 @@ protected function getRootDocument():Document {
381
416
return $ this ->ownerDocument ;
382
417
}
383
418
419
+ private function getBooleanAttribute (string $ attribute ):bool {
420
+ return $ this ->hasAttribute ($ attribute );
421
+ }
422
+
423
+ private function setBooleanAttribute (string $ attribute , bool $ value ) {
424
+ if (($ this ->tagName === "input " && $ this ->type === "radio " && $ attribute === "checked " )
425
+ || ($ this ->tagName === "option " && !$ this ->parentNode ->hasAttribute ("multiple " )) && $ attribute === "selected " ) {
426
+ if ($ form = $ this ->closest ("form " )) {
427
+ $ elementName = $ this ->getAttribute ("name " );
428
+ if (!$ elementName && $ this ->tagName === "option " ) {
429
+ $ elementName = $ this ->parentNode ->getAttribute ("name " );
430
+ }
431
+
432
+ $ this ->removeAttributeFromNamedElementAndChildren (
433
+ $ form ,
434
+ $ elementName ,
435
+ $ attribute
436
+ );
437
+ }
438
+ }
439
+ if ($ value ) {
440
+ $ this ->setAttribute ($ attribute , $ attribute );
441
+ }
442
+ else {
443
+ $ this ->removeAttribute ($ attribute );
444
+ }
445
+ }
446
+
384
447
private function value_set_select (string $ newValue ):void {
385
448
$ options = $ this ->getElementsByTagName ('option ' );
386
449
$ selectedIndexes = [];
0 commit comments