happy-dom 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (59) hide show
  1. package/lib/config/ElementTag.d.ts +6 -3
  2. package/lib/config/ElementTag.js +6 -3
  3. package/lib/config/ElementTag.js.map +1 -1
  4. package/lib/config/NonImplemenetedElementClasses.js +0 -3
  5. package/lib/config/NonImplemenetedElementClasses.js.map +1 -1
  6. package/lib/nodes/html-input-element/HTMLInputElement.d.ts +1 -1
  7. package/lib/nodes/html-input-element/HTMLInputElement.js +1 -1
  8. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  9. package/lib/nodes/html-input-element/IHTMLInputElement.d.ts +1 -1
  10. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.d.ts +34 -0
  11. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js +58 -0
  12. package/lib/nodes/html-opt-group-element/HTMLOptGroupElement.js.map +1 -0
  13. package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.d.ts +11 -0
  14. package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.js +3 -0
  15. package/lib/nodes/html-opt-group-element/IHTMLOptGroupElement.js.map +1 -0
  16. package/lib/nodes/html-option-element/HTMLOptionElement.d.ts +72 -0
  17. package/lib/nodes/html-option-element/HTMLOptionElement.js +111 -0
  18. package/lib/nodes/html-option-element/HTMLOptionElement.js.map +1 -0
  19. package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.d.ts +11 -0
  20. package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.js +18 -0
  21. package/lib/nodes/html-option-element/HTMLOptionElementValueSanitizer.js.map +1 -0
  22. package/lib/nodes/html-option-element/HTMLOptionsCollection.d.ts +43 -0
  23. package/lib/nodes/html-option-element/HTMLOptionsCollection.js +80 -0
  24. package/lib/nodes/html-option-element/HTMLOptionsCollection.js.map +1 -0
  25. package/lib/nodes/html-option-element/IHTMLOptionElement.d.ts +16 -0
  26. package/lib/nodes/html-option-element/IHTMLOptionElement.js +3 -0
  27. package/lib/nodes/html-option-element/IHTMLOptionElement.js.map +1 -0
  28. package/lib/nodes/html-option-element/IHTMLOptionsCollection.d.ts +26 -0
  29. package/lib/nodes/html-option-element/IHTMLOptionsCollection.js +3 -0
  30. package/lib/nodes/html-option-element/IHTMLOptionsCollection.js.map +1 -0
  31. package/lib/nodes/html-select-element/HTMLSelectElement.d.ts +128 -0
  32. package/lib/nodes/html-select-element/HTMLSelectElement.js +215 -0
  33. package/lib/nodes/html-select-element/HTMLSelectElement.js.map +1 -0
  34. package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.d.ts +11 -0
  35. package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.js +18 -0
  36. package/lib/nodes/html-select-element/HTMLSelectElementValueSanitizer.js.map +1 -0
  37. package/lib/nodes/html-select-element/IHTMLSelectElement.d.ts +26 -0
  38. package/lib/nodes/html-select-element/IHTMLSelectElement.js +3 -0
  39. package/lib/nodes/html-select-element/IHTMLSelectElement.js.map +1 -0
  40. package/lib/nodes/{html-input-element → validity-state}/ValidityState.d.ts +3 -2
  41. package/lib/nodes/{html-input-element → validity-state}/ValidityState.js +12 -2
  42. package/lib/nodes/validity-state/ValidityState.js.map +1 -0
  43. package/package.json +2 -2
  44. package/src/config/ElementTag.ts +6 -3
  45. package/src/config/NonImplemenetedElementClasses.ts +0 -3
  46. package/src/nodes/html-input-element/HTMLInputElement.ts +1 -1
  47. package/src/nodes/html-input-element/IHTMLInputElement.ts +1 -1
  48. package/src/nodes/html-opt-group-element/HTMLOptGroupElement.ts +54 -0
  49. package/src/nodes/html-opt-group-element/IHTMLOptGroupElement.ts +12 -0
  50. package/src/nodes/html-option-element/HTMLOptionElement.ts +117 -0
  51. package/src/nodes/html-option-element/HTMLOptionElementValueSanitizer.ts +15 -0
  52. package/src/nodes/html-option-element/HTMLOptionsCollection.ts +94 -0
  53. package/src/nodes/html-option-element/IHTMLOptionElement.ts +17 -0
  54. package/src/nodes/html-option-element/IHTMLOptionsCollection.ts +33 -0
  55. package/src/nodes/html-select-element/HTMLSelectElement.ts +239 -0
  56. package/src/nodes/html-select-element/HTMLSelectElementValueSanitizer.ts +15 -0
  57. package/src/nodes/html-select-element/IHTMLSelectElement.ts +27 -0
  58. package/src/nodes/{html-input-element → validity-state}/ValidityState.ts +13 -5
  59. package/lib/nodes/html-input-element/ValidityState.js.map +0 -1
@@ -32,13 +32,10 @@ export default [
32
32
  'HTMLMediaElement',
33
33
  'HTMLMeterElement',
34
34
  'HTMLModElement',
35
- 'HTMLOptGroupElement',
36
- 'HTMLOptionElement',
37
35
  'HTMLOutputElement',
38
36
  'HTMLPictureElement',
39
37
  'HTMLProgressElement',
40
38
  'HTMLQuoteElement',
41
- 'HTMLSelectElement',
42
39
  'HTMLSourceElement',
43
40
  'HTMLSpanElement',
44
41
  'HTMLTableCaptionElement',
@@ -1,6 +1,6 @@
1
1
  import File from '../../file/File';
2
2
  import HTMLElement from '../html-element/HTMLElement';
3
- import ValidityState from './ValidityState';
3
+ import ValidityState from '../validity-state/ValidityState';
4
4
  import DOMException from '../../exception/DOMException';
5
5
  import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum';
6
6
  import Event from '../../event/Event';
@@ -2,7 +2,7 @@ import File from '../../file/File';
2
2
  import IHTMLElement from '../html-element/IHTMLElement';
3
3
  import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
4
4
  import HTMLInputElementSelectionModeEnum from './HTMLInputElementSelectionModeEnum';
5
- import ValidityState from './ValidityState';
5
+ import ValidityState from '../validity-state/ValidityState';
6
6
 
7
7
  /**
8
8
  * HTML Input Element.
@@ -0,0 +1,54 @@
1
+ import HTMLElement from '../html-element/HTMLElement';
2
+ import IHTMLOptGroupElement from './IHTMLOptGroupElement';
3
+
4
+ /**
5
+ * HTML Opt Group Element.
6
+ *
7
+ * Reference:
8
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement.
9
+ */
10
+ export default class HTMLOptGroupElement extends HTMLElement implements IHTMLOptGroupElement {
11
+ /**
12
+ * Returns label.
13
+ *
14
+ * @returns Label.
15
+ */
16
+ public get label(): string {
17
+ return this.getAttributeNS(null, 'label') || '';
18
+ }
19
+
20
+ /**
21
+ * Sets label.
22
+ *
23
+ * @param label Label.
24
+ */
25
+ public set label(label: string) {
26
+ if (!label) {
27
+ this.removeAttributeNS(null, 'label');
28
+ } else {
29
+ this.setAttributeNS(null, 'label', label);
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Returns disabled.
35
+ *
36
+ * @returns Disabled.
37
+ */
38
+ public get disabled(): boolean {
39
+ return this.getAttributeNS(null, 'disabled') !== null;
40
+ }
41
+
42
+ /**
43
+ * Sets disabled.
44
+ *
45
+ * @param disabled Disabled.
46
+ */
47
+ public set disabled(disabled: boolean) {
48
+ if (!disabled) {
49
+ this.removeAttributeNS(null, 'disabled');
50
+ } else {
51
+ this.setAttributeNS(null, 'disabled', '');
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,12 @@
1
+ import IHTMLElement from '../html-element/IHTMLElement';
2
+
3
+ /**
4
+ * HTML Opt Group Element.
5
+ *
6
+ * Reference:
7
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptGroupElement.
8
+ */
9
+ export default interface IHTMLOptGroupElement extends IHTMLElement {
10
+ disabled: boolean;
11
+ label: string;
12
+ }
@@ -0,0 +1,117 @@
1
+ import HTMLElement from '../html-element/HTMLElement';
2
+ import IHTMLElement from '../html-element/IHTMLElement';
3
+ import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
4
+ import HTMLOptionElementValueSanitizer from './HTMLOptionElementValueSanitizer';
5
+ import IHTMLOptionElement from './IHTMLOptionElement';
6
+
7
+ /**
8
+ * HTML Option Element.
9
+ *
10
+ * Reference:
11
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
12
+ */
13
+ export default class HTMLOptionElement extends HTMLElement implements IHTMLOptionElement {
14
+ public _index: number;
15
+
16
+ /**
17
+ * Returns inner text, which is the rendered appearance of text.
18
+ *
19
+ * @returns Inner text.
20
+ */
21
+ public get text(): string {
22
+ return this.innerText;
23
+ }
24
+
25
+ /**
26
+ * Sets the inner text, which is the rendered appearance of text.
27
+ *
28
+ * @param innerText Inner text.
29
+ */
30
+ public set text(text: string) {
31
+ this.innerText = text;
32
+ }
33
+
34
+ /**
35
+ * Returns index.
36
+ *
37
+ * @returns Index.
38
+ */
39
+ public get index(): number {
40
+ return this._index;
41
+ }
42
+
43
+ /**
44
+ * Returns the parent form element.
45
+ *
46
+ * @returns Form.
47
+ */
48
+ public get form(): IHTMLFormElement {
49
+ let parent = <IHTMLElement>this.parentNode;
50
+ while (parent && parent.tagName !== 'FORM') {
51
+ parent = <IHTMLElement>parent.parentNode;
52
+ }
53
+ return <IHTMLFormElement>parent;
54
+ }
55
+
56
+ /**
57
+ * Returns selected.
58
+ *
59
+ * @returns Selected.
60
+ */
61
+ public get selected(): boolean {
62
+ return this.getAttributeNS(null, 'selected') !== null;
63
+ }
64
+
65
+ /**
66
+ * Sets selected.
67
+ *
68
+ * @param selected Selected.
69
+ */
70
+ public set selected(selected: boolean) {
71
+ if (!selected) {
72
+ this.removeAttributeNS(null, 'selected');
73
+ } else {
74
+ this.setAttributeNS(null, 'selected', '');
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Returns disabled.
80
+ *
81
+ * @returns Disabled.
82
+ */
83
+ public get disabled(): boolean {
84
+ return this.getAttributeNS(null, 'disabled') !== null;
85
+ }
86
+
87
+ /**
88
+ * Sets disabled.
89
+ *
90
+ * @param disabled Disabled.
91
+ */
92
+ public set disabled(disabled: boolean) {
93
+ if (!disabled) {
94
+ this.removeAttributeNS(null, 'disabled');
95
+ } else {
96
+ this.setAttributeNS(null, 'disabled', '');
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Returns value.
102
+ *
103
+ * @returns Value.
104
+ */
105
+ public get value(): string {
106
+ return this.getAttributeNS(null, 'value') || '';
107
+ }
108
+
109
+ /**
110
+ * Sets value.
111
+ *
112
+ * @param value Value.
113
+ */
114
+ public set value(value: string) {
115
+ this.setAttributeNS(null, 'value', HTMLOptionElementValueSanitizer.sanitize(value));
116
+ }
117
+ }
@@ -0,0 +1,15 @@
1
+ const NEW_LINES_REGEXP = /[\n\r]/gm;
2
+
3
+ /**
4
+ * HTML select element value sanitizer.
5
+ */
6
+ export default class HTMLOptionElementValueSanitizer {
7
+ /**
8
+ * Sanitizes a value.
9
+ *
10
+ * @param value Value.
11
+ */
12
+ public static sanitize(value: string): string {
13
+ return value.trim().replace(NEW_LINES_REGEXP, '');
14
+ }
15
+ }
@@ -0,0 +1,94 @@
1
+ import DOMException from '../../exception/DOMException';
2
+ import HTMLCollection from '../element/HTMLCollection';
3
+ import HTMLOptGroupElement from '../html-opt-group-element/HTMLOptGroupElement';
4
+ import HTMLOptionElement from './HTMLOptionElement';
5
+ import IHTMLOptionsCollection from './IHTMLOptionsCollection';
6
+
7
+ /**
8
+ * HTML Options Collection.
9
+ *
10
+ * Reference:
11
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection.
12
+ */
13
+ export default class HTMLOptionsCollection
14
+ extends HTMLCollection
15
+ implements IHTMLOptionsCollection
16
+ {
17
+ public _selectedIndex: number;
18
+
19
+ /**
20
+ * Returns selectedIndex.
21
+ *
22
+ * @returns SelectedIndex.
23
+ */
24
+ public get selectedIndex(): number {
25
+ return this._selectedIndex;
26
+ }
27
+
28
+ /**
29
+ * Sets selectedIndex.
30
+ *
31
+ * @param selectedIndex SelectedIndex.
32
+ */
33
+ public set selectedIndex(selectedIndex: number) {
34
+ this._selectedIndex = selectedIndex;
35
+ }
36
+
37
+ /**
38
+ * Returns item by index.
39
+ *
40
+ * @param index Index.
41
+ */
42
+ public item(index: number): HTMLOptionElement | HTMLOptGroupElement {
43
+ return this[index];
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param element
49
+ * @param before
50
+ */
51
+ public add(
52
+ element: HTMLOptionElement | HTMLOptGroupElement,
53
+ before?: number | HTMLOptionElement | HTMLOptGroupElement
54
+ ): void {
55
+ if (!before && before !== 0) {
56
+ this.push(element);
57
+ return;
58
+ }
59
+
60
+ if (!Number.isNaN(Number(before))) {
61
+ if (before < 0) {
62
+ return;
63
+ }
64
+
65
+ this.splice(<number>before, 0, element);
66
+ return;
67
+ }
68
+
69
+ const idx = this.findIndex((element) => element === before);
70
+ if (idx === -1) {
71
+ throw new DOMException(
72
+ "Failed to execute 'add' on 'DOMException': The node before which the new node is to be inserted is not a child of this node."
73
+ );
74
+ }
75
+
76
+ this.splice(idx, 0, element);
77
+ }
78
+
79
+ /**
80
+ * Removes indexed element from collection.
81
+ *
82
+ * @param index Index.
83
+ */
84
+ public remove(index: number): void {
85
+ this.splice(index, 1);
86
+ if (index === this.selectedIndex) {
87
+ if (this.length) {
88
+ this.selectedIndex = 0;
89
+ } else {
90
+ this.selectedIndex = -1;
91
+ }
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,17 @@
1
+ import IHTMLElement from '../html-element/IHTMLElement';
2
+ import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
3
+
4
+ /**
5
+ * HTML Option Element.
6
+ *
7
+ * Reference:
8
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
9
+ */
10
+ export default interface IHTMLOptionElement extends IHTMLElement {
11
+ readonly form: IHTMLFormElement;
12
+ readonly index: number;
13
+ selected: boolean;
14
+ value: string;
15
+ text: string;
16
+ disabled: boolean;
17
+ }
@@ -0,0 +1,33 @@
1
+ import IHTMLCollection from '../element/IHTMLCollection';
2
+ import IHTMLOptGroupElement from '../html-opt-group-element/IHTMLOptGroupElement';
3
+ import IHTMLOptionElement from './IHTMLOptionElement';
4
+
5
+ /**
6
+ * HTML Options Collection.
7
+ *
8
+ * Reference:
9
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection.
10
+ */
11
+ export default interface IHTMLOptionsCollection
12
+ extends IHTMLCollection<IHTMLOptionElement | IHTMLOptGroupElement> {
13
+ selectedIndex: number;
14
+ length: number;
15
+
16
+ /**
17
+ * Adds new option to collection.
18
+ *
19
+ * @param element HTMLOptionElement or HTMLOptGroupElement to add.
20
+ * @param before HTMLOptionElement or index number.
21
+ */
22
+ add(
23
+ element: IHTMLOptionElement | IHTMLOptGroupElement,
24
+ before?: number | IHTMLOptionElement | IHTMLOptGroupElement
25
+ ): void;
26
+
27
+ /**
28
+ * Removes option element from the collection.
29
+ *
30
+ * @param index Index.
31
+ */
32
+ remove(index: number): void;
33
+ }
@@ -0,0 +1,239 @@
1
+ import DOMException from '../../exception/DOMException';
2
+ import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum';
3
+ import HTMLElement from '../html-element/HTMLElement';
4
+ import IHTMLElement from '../html-element/IHTMLElement';
5
+ import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
6
+ import ValidityState from '../validity-state/ValidityState';
7
+ import IHTMLLabelElement from '../html-label-element/IHTMLLabelElement';
8
+ import HTMLOptGroupElement from '../html-opt-group-element/HTMLOptGroupElement';
9
+ import HTMLOptionElement from '../html-option-element/HTMLOptionElement';
10
+ import HTMLOptionsCollection from '../html-option-element/HTMLOptionsCollection';
11
+ import IHTMLOptionsCollection from '../html-option-element/IHTMLOptionsCollection';
12
+ import INodeList from '../node/INodeList';
13
+ import HTMLSelectElementValueSanitizer from './HTMLSelectElementValueSanitizer';
14
+ import IHTMLSelectElement from './IHTMLSelectElement';
15
+
16
+ /**
17
+ * HTML Select Element.
18
+ *
19
+ * Reference:
20
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement.
21
+ */
22
+ export default class HTMLSelectElement extends HTMLElement implements IHTMLSelectElement {
23
+ public type: string;
24
+ public labels: INodeList<IHTMLLabelElement>;
25
+
26
+ public _value = null;
27
+ public _selectedIndex = -1;
28
+ public _options: IHTMLOptionsCollection = null;
29
+
30
+ /**
31
+ * Returns name.
32
+ *
33
+ * @returns Name.
34
+ */
35
+ public get name(): string {
36
+ return this.getAttributeNS(null, 'name') || '';
37
+ }
38
+
39
+ /**
40
+ * Sets name.
41
+ *
42
+ * @param name Name.
43
+ */
44
+ public set name(name: string) {
45
+ this.setAttributeNS(null, 'name', name);
46
+ }
47
+
48
+ /**
49
+ * Returns disabled.
50
+ *
51
+ * @returns Disabled.
52
+ */
53
+ public get disabled(): boolean {
54
+ return this.getAttributeNS(null, 'disabled') !== null;
55
+ }
56
+
57
+ /**
58
+ * Sets disabled.
59
+ *
60
+ * @param disabled Disabled.
61
+ */
62
+ public set disabled(disabled: boolean) {
63
+ if (!disabled) {
64
+ this.removeAttributeNS(null, 'disabled');
65
+ } else {
66
+ this.setAttributeNS(null, 'disabled', '');
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Returns multiple.
72
+ *
73
+ * @returns Multiple.
74
+ */
75
+ public get multiple(): boolean {
76
+ return this.getAttributeNS(null, 'multiple') !== null;
77
+ }
78
+
79
+ /**
80
+ * Sets multiple.
81
+ *
82
+ * @param multiple Multiple.
83
+ */
84
+ public set multiple(multiple: boolean) {
85
+ if (!multiple) {
86
+ this.removeAttributeNS(null, 'multiple');
87
+ } else {
88
+ this.setAttributeNS(null, 'multiple', '');
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Returns autofocus.
94
+ *
95
+ * @returns Autofocus.
96
+ */
97
+ public get autofocus(): boolean {
98
+ return this.getAttributeNS(null, 'autofocus') !== null;
99
+ }
100
+
101
+ /**
102
+ * Sets autofocus.
103
+ *
104
+ * @param autofocus Autofocus.
105
+ */
106
+ public set autofocus(autofocus: boolean) {
107
+ if (!autofocus) {
108
+ this.removeAttributeNS(null, 'autofocus');
109
+ } else {
110
+ this.setAttributeNS(null, 'autofocus', '');
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Returns required.
116
+ *
117
+ * @returns Required.
118
+ */
119
+ public get required(): boolean {
120
+ return this.getAttributeNS(null, 'required') !== null;
121
+ }
122
+
123
+ /**
124
+ * Sets required.
125
+ *
126
+ * @param required Required.
127
+ */
128
+ public set required(required: boolean) {
129
+ if (!required) {
130
+ this.removeAttributeNS(null, 'required');
131
+ } else {
132
+ this.setAttributeNS(null, 'required', '');
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Returns value.
138
+ *
139
+ * @returns Value.
140
+ */
141
+ public get value(): string {
142
+ return this._value;
143
+ }
144
+
145
+ /**
146
+ * Sets value.
147
+ *
148
+ * @param value Value.
149
+ */
150
+ public set value(value: string) {
151
+ this._value = HTMLSelectElementValueSanitizer.sanitize(value);
152
+
153
+ const idx = this.options.findIndex((o) => o.nodeValue === value);
154
+ if (idx > -1) {
155
+ this._selectedIndex = idx;
156
+ }
157
+ }
158
+
159
+ /**
160
+ * Returns value.
161
+ *
162
+ * @returns Value.
163
+ */
164
+ public get selectedIndex(): number {
165
+ return this._options ? this._options.selectedIndex : -1;
166
+ }
167
+
168
+ /**
169
+ * Sets value.
170
+ *
171
+ * @param value Value.
172
+ */
173
+ public set selectedIndex(value: number) {
174
+ if (this.options.length - 1 > value || value < 0) {
175
+ throw new DOMException(
176
+ 'Select elements selected index must be valid',
177
+ DOMExceptionNameEnum.indexSizeError
178
+ );
179
+ }
180
+
181
+ this._options.selectedIndex = value;
182
+ }
183
+
184
+ /**
185
+ * Returns the parent form element.
186
+ *
187
+ * @returns Form.
188
+ */
189
+ public get form(): IHTMLFormElement {
190
+ let parent = <IHTMLElement>this.parentNode;
191
+ while (parent && parent.tagName !== 'FORM') {
192
+ parent = <IHTMLElement>parent.parentNode;
193
+ }
194
+ return <IHTMLFormElement>parent;
195
+ }
196
+
197
+ /**
198
+ * Returns validity state.
199
+ *
200
+ * @returns Validity state.
201
+ */
202
+ public get validity(): ValidityState {
203
+ return new ValidityState(this);
204
+ }
205
+
206
+ /**
207
+ * Returns "true" if it will validate.
208
+ *
209
+ * @returns "true" if it will validate.
210
+ */
211
+ public get willValidate(): boolean {
212
+ return (
213
+ this.type !== 'hidden' &&
214
+ this.type !== 'reset' &&
215
+ this.type !== 'button' &&
216
+ !this.disabled &&
217
+ !this['readOnly']
218
+ );
219
+ }
220
+
221
+ /**
222
+ * Returns options.
223
+ *
224
+ * @returns Options.
225
+ */
226
+ public get options(): IHTMLOptionsCollection {
227
+ if (this._options === null) {
228
+ this._options = new HTMLOptionsCollection();
229
+ const childs = <INodeList<IHTMLElement>>this.childNodes;
230
+ for (const child of childs) {
231
+ if (child.tagName === 'OPTION') {
232
+ this._options.add(<HTMLOptionElement | HTMLOptGroupElement>child);
233
+ }
234
+ }
235
+ }
236
+
237
+ return this._options;
238
+ }
239
+ }
@@ -0,0 +1,15 @@
1
+ const NEW_LINES_REGEXP = /[\n\r]/gm;
2
+
3
+ /**
4
+ * HTML select element value sanitizer.
5
+ */
6
+ export default class HTMLSelectElementValueSanitizer {
7
+ /**
8
+ * Sanitizes a value.
9
+ *
10
+ * @param value Value.
11
+ */
12
+ public static sanitize(value: string): string {
13
+ return value.replace(NEW_LINES_REGEXP, '');
14
+ }
15
+ }
@@ -0,0 +1,27 @@
1
+ import IHTMLElement from '../html-element/IHTMLElement';
2
+ import IHTMLFormElement from '../html-form-element/IHTMLFormElement';
3
+ import IHTMLLabelElement from '../html-label-element/IHTMLLabelElement';
4
+ import INodeList from '../node/INodeList';
5
+ import IHTMLOptionsCollection from '../html-option-element/IHTMLOptionsCollection';
6
+ import ValidityState from '../validity-state/ValidityState';
7
+
8
+ /**
9
+ * HTML Select Element.
10
+ *
11
+ * Reference:
12
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLSelectElement.
13
+ */
14
+ export default interface IHTMLSelectElement extends IHTMLElement {
15
+ readonly form: IHTMLFormElement;
16
+ readonly labels: INodeList<IHTMLLabelElement>;
17
+ type: string;
18
+ autofocus: boolean;
19
+ disabled: boolean;
20
+ options: IHTMLOptionsCollection;
21
+ selectedIndex: number;
22
+ validity: ValidityState;
23
+ value: string;
24
+ willValidate: boolean;
25
+ name: string;
26
+ multiple: boolean;
27
+ }