@htmltools/hdom 0.1.3 → 0.1.5

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.
package/lib/hdom.d.ts CHANGED
@@ -44,9 +44,12 @@ export class hdom {
44
44
  /**
45
45
  * @param {string} forId
46
46
  * @param {string} text
47
+ * @param {Object<string,string>} [extraAtts]
47
48
  * @returns {HTMLElement}
48
49
  */
49
- static createLabelElement(forId: string, text: string): HTMLElement;
50
+ static createLabelElement(forId: string, text: string, extraAtts?: {
51
+ [x: string]: string;
52
+ }): HTMLElement;
50
53
  /**
51
54
  * @param {URL|string|undefined} url
52
55
  * @param {Node|string|number} eLinkText
@@ -160,10 +163,10 @@ export class hdom {
160
163
  */
161
164
  static setFocusTo(e: string | HTMLElement): void;
162
165
  /**
163
- * @param {string|HTMLElement} e
166
+ * @param {string|HTMLElement|RadioNodeList} e
164
167
  * @param {string|number} value
165
168
  */
166
- static setFormElementValue(e: string | HTMLElement, value: string | number): void;
169
+ static setFormElementValue(e: string | HTMLElement | RadioNodeList, value: string | number): void;
167
170
  /**
168
171
  * @param {string|Element} e
169
172
  * @param {string} text
package/lib/hdom.js CHANGED
@@ -99,10 +99,12 @@ export class hdom {
99
99
  /**
100
100
  * @param {string} forId
101
101
  * @param {string} text
102
+ * @param {Object<string,string>} [extraAtts]
102
103
  * @returns {HTMLElement}
103
104
  */
104
- static createLabelElement(forId, text) {
105
- const el = this.createElement("label", { for: forId });
105
+ static createLabelElement(forId, text, extraAtts = {}) {
106
+ const attributes = { for: forId, ...extraAtts };
107
+ const el = this.createElement("label", attributes);
106
108
  this.setTextValue(el, text);
107
109
  return el;
108
110
  }
@@ -157,7 +159,7 @@ export class hdom {
157
159
  * @returns {{label:HTMLElement,select:HTMLElement}}
158
160
  */
159
161
  static createSelectElementWithLabel(id, label, options) {
160
- const labelEl = this.createLabelElement(id, "label");
162
+ const labelEl = this.createLabelElement(id, label);
161
163
  return {
162
164
  label: labelEl,
163
165
  select: this.createSelectElement(id, options),
@@ -353,15 +355,16 @@ export class hdom {
353
355
  }
354
356
 
355
357
  /**
356
- * @param {string|HTMLElement} e
358
+ * @param {string|HTMLElement|RadioNodeList} e
357
359
  * @param {string|number} value
358
360
  */
359
361
  static setFormElementValue(e, value) {
360
- const elem = this.getElement(e);
362
+ const elem = typeof e === "string" ? this.getElement(e) : e;
361
363
  if (
362
364
  elem instanceof HTMLInputElement ||
363
365
  elem instanceof HTMLTextAreaElement ||
364
- elem instanceof HTMLSelectElement
366
+ elem instanceof HTMLSelectElement ||
367
+ elem instanceof RadioNodeList
365
368
  ) {
366
369
  elem.value = value.toString();
367
370
  } else if (elem instanceof HTMLElement) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmltools/hdom",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Tools to interact with the HTML DOM.",
5
5
  "license": "MIT",
6
6
  "repository": {