@zywave/zui-slider 4.0.15 → 4.1.0-pre.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.
- package/dist/zui-slider.js +16 -28
- package/dist/zui-slider.js.map +1 -1
- package/package.json +3 -3
- package/test/zui-slider.test.ts +13 -19
package/dist/zui-slider.js
CHANGED
|
@@ -4,18 +4,6 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
-
};
|
|
18
|
-
var _ZuiSlider_defaultValue, _ZuiSlider_value;
|
|
19
7
|
import { ZuiFormAssociatedElement } from '@zywave/zui-base';
|
|
20
8
|
import { html } from 'lit';
|
|
21
9
|
import { property } from 'lit/decorators.js';
|
|
@@ -47,8 +35,8 @@ const DEFAULT_MAX = 100;
|
|
|
47
35
|
export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
48
36
|
constructor() {
|
|
49
37
|
super(...arguments);
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
this.#defaultValue = `${DEFAULT_MAX / 2}`;
|
|
39
|
+
this.#value = `${DEFAULT_MAX / 2}`;
|
|
52
40
|
/**
|
|
53
41
|
* Represents the maximum permitted value
|
|
54
42
|
*/
|
|
@@ -73,20 +61,22 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
73
61
|
return this.value;
|
|
74
62
|
}
|
|
75
63
|
formResetCallback() {
|
|
76
|
-
this.value =
|
|
64
|
+
this.value = this.#defaultValue;
|
|
77
65
|
}
|
|
66
|
+
#defaultValue;
|
|
67
|
+
#value;
|
|
78
68
|
get value() {
|
|
79
|
-
return
|
|
69
|
+
return this.#value;
|
|
80
70
|
}
|
|
81
71
|
set value(val) {
|
|
82
|
-
const oldVal =
|
|
72
|
+
const oldVal = this.#value;
|
|
83
73
|
val = this._ensureValidValue(val);
|
|
84
|
-
|
|
85
|
-
this._setFormValue(
|
|
74
|
+
this.#value = val;
|
|
75
|
+
this._setFormValue(this.#value);
|
|
86
76
|
this.requestUpdate('value', oldVal);
|
|
87
77
|
}
|
|
88
78
|
get valueAsNumber() {
|
|
89
|
-
return parseFloat(
|
|
79
|
+
return parseFloat(this.#value);
|
|
90
80
|
}
|
|
91
81
|
get progress() {
|
|
92
82
|
return ((this.valueAsNumber - this.min) / (this.max - this.min)) * 100;
|
|
@@ -95,14 +85,13 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
95
85
|
return [super.styles, style];
|
|
96
86
|
}
|
|
97
87
|
connectedCallback() {
|
|
98
|
-
var _a, _b, _c;
|
|
99
88
|
super.connectedCallback();
|
|
100
89
|
// we want to go a little faster than LitElement and behave more like native HTML Form Associated Elements
|
|
101
|
-
let value =
|
|
102
|
-
const max =
|
|
103
|
-
const min =
|
|
90
|
+
let value = this.getAttribute('value') ?? this.value;
|
|
91
|
+
const max = this.getAttribute('max') ?? this.max;
|
|
92
|
+
const min = this.getAttribute('min') ?? this.min;
|
|
104
93
|
value = this._ensureValidValue(value, min, max);
|
|
105
|
-
|
|
94
|
+
this.#defaultValue = value;
|
|
106
95
|
this._setFormValue(value.toString());
|
|
107
96
|
}
|
|
108
97
|
render() {
|
|
@@ -142,8 +131,8 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
142
131
|
if (value === '') {
|
|
143
132
|
return value;
|
|
144
133
|
}
|
|
145
|
-
min = min
|
|
146
|
-
max = max
|
|
134
|
+
min = min ?? this.min;
|
|
135
|
+
max = max ?? this.max;
|
|
147
136
|
if (typeof value === 'string') {
|
|
148
137
|
value = parseFloat(value);
|
|
149
138
|
}
|
|
@@ -162,7 +151,6 @@ export class ZuiSlider extends ZuiFormAssociatedElement {
|
|
|
162
151
|
return value.toString();
|
|
163
152
|
}
|
|
164
153
|
}
|
|
165
|
-
_ZuiSlider_defaultValue = new WeakMap(), _ZuiSlider_value = new WeakMap();
|
|
166
154
|
__decorate([
|
|
167
155
|
property()
|
|
168
156
|
], ZuiSlider.prototype, "value", null);
|
package/dist/zui-slider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zui-slider.js","sourceRoot":"","sources":["../src/zui-slider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO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AK,GAAG,GAAG,EAAE;YACtB,KAAK,GAAG,GAAG,CAAC;SACb;QAED,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;CACF;;AAxHC;IADC,QAAQ,EAAE;sCAGV;AAiB2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAS;AAKU;IAA7C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;sCAAW;AAK5B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAAU;AAKc;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;yCAAgB;AAwFpE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { ZuiFormAssociatedElement } from '@zywave/zui-base';\nimport { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { style } from './zui-slider-css.js';\n\nconst DEFAULT_MAX = 100;\n\n/**\n * A range form control for choosing values along a slider.\n * @element zui-slider\n *\n * @attr {string | null} [name=null] - The name of this element that is associated with form submission\n * @attr {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @attr {boolean} [readonly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @attr {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @attr {number} [value=50] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n *\n * @prop {string | null} [name=null] - The name of this element that is associated with form submission\n * @prop {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @prop {boolean} [readOnly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @prop {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @prop {number} [valueAsNumber=50] - Returns the value of the element, interpreted as one of the following, in order: A number, NaN if conversion is impossible\n * @prop {string} [value='50'] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n * @prop {number} [progress=50] - Determines visual placement of the slider thumb along the line\n *\n * @cssprop [--zui-slider-thumb-size=1.875rem (30px)] - Point of contact to grab and slide to change value\n *\n * @event {CustomEvent} change - Fires when value changes, details contain `value`\n */\nexport class ZuiSlider extends ZuiFormAssociatedElement {\n protected get _formControlSelector() {\n return 'input';\n }\n\n protected get _formValue() {\n return this.value;\n }\n\n protected formResetCallback() {\n this.value = this.#defaultValue;\n }\n\n #defaultValue = `${DEFAULT_MAX / 2}`;\n\n #value = `${DEFAULT_MAX / 2}`;\n\n @property()\n get value() {\n return this.#value;\n }\n\n set value(val) {\n const oldVal = this.#value;\n val = this._ensureValidValue(val);\n this.#value = val;\n this._setFormValue(this.#value);\n this.requestUpdate('value', oldVal);\n }\n\n get valueAsNumber() {\n return parseFloat(this.#value);\n }\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number }) min = 0;\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number, attribute: 'max' }) max = 100;\n\n /**\n * Represents the stepping interval, used both for user interface and validation purposes\n */\n @property({ type: Number }) step = 0;\n\n /**\n * Represents that this control must be filled in for form submission\n */\n @property({ type: Boolean, attribute: 'no-text' }) noText = false;\n\n get progress() {\n return ((this.valueAsNumber - this.min) / (this.max - this.min)) * 100;\n }\n\n static get styles() {\n return [super.styles, style];\n }\n\n connectedCallback() {\n super.connectedCallback();\n\n // we want to go a little faster than LitElement and behave more like native HTML Form Associated Elements\n let value = this.getAttribute('value') ?? this.value;\n const max = this.getAttribute('max') ?? this.max;\n const min = this.getAttribute('min') ?? this.min;\n\n value = this._ensureValidValue(value, min, max);\n\n this.#defaultValue = value;\n this._setFormValue(value.toString());\n }\n\n render() {\n const progressColor = this.disabled ? 'var(--zui-gray)' : 'var(--zui-blue)';\n const styles = {\n background: `linear-gradient(to right, ${progressColor} 0%, ${progressColor} ${this.progress}%, var(--zui-gray-200) ${this.progress}%, var(--zui-gray-200) 100%)`,\n };\n return html`<input\n style=${styleMap(styles)}\n type=\"range\"\n .value=\"${this.value}\"\n .min=\"${this.min}\"\n .max=\"${this.max}\"\n .step=\"${this.step}\"\n ?disabled=\"${this.disabled}\"\n @input=\"${this._onInput}\"\n @change=\"${this._onChange}\"\n />${this._renderText()}`;\n }\n\n private _renderText() {\n if (this.noText) {\n return html``;\n }\n const thumbOffset = `var(--zui-slider-thumb-size) * ${this.progress / 100}`;\n const styles = {\n left: `calc(${this.progress}% - ${thumbOffset} + 0.125rem)`,\n };\n return html`<span style=${styleMap(styles)}>${this.value}</span>`;\n }\n\n private _onInput(e: Event) {\n this.value = (e.target as HTMLInputElement).value;\n }\n\n private _onChange() {\n this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));\n }\n\n private _ensureValidValue(value: string | number, min?: number | string | null, max?: number | string | null) {\n if (value === '') {\n return value;\n }\n min = min ?? this.min;\n max = max ?? this.max;\n\n if (typeof value === 'string') {\n value = parseFloat(value);\n }\n if (typeof min === 'string') {\n min = parseFloat(min);\n }\n if (typeof max === 'string') {\n max = parseFloat(max);\n }\n\n if (value < min) {\n value = min;\n } else if (value > max) {\n value = max;\n }\n\n return value.toString();\n }\n}\n\nwindow.customElements.define('zui-slider', ZuiSlider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'zui-slider': ZuiSlider;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"zui-slider.js","sourceRoot":"","sources":["../src/zui-slider.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAC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Q,EAAE,CAAC;YAC5B,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;QACxB,CAAC;QAED,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YAChB,KAAK,GAAG,GAAG,CAAC;QACd,CAAC;aAAM,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;YACvB,KAAK,GAAG,GAAG,CAAC;QACd,CAAC;QAED,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;CACF;AAxHC;IADC,QAAQ,EAAE;sCAGV;AAiB2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sCAAS;AAKU;IAA7C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;sCAAW;AAK5B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAAU;AAKc;IAAlD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;yCAAgB;AAwFpE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { ZuiFormAssociatedElement } from '@zywave/zui-base';\nimport { html } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styleMap } from 'lit/directives/style-map.js';\nimport { style } from './zui-slider-css.js';\n\nconst DEFAULT_MAX = 100;\n\n/**\n * A range form control for choosing values along a slider.\n * @element zui-slider\n *\n * @attr {string | null} [name=null] - The name of this element that is associated with form submission\n * @attr {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @attr {boolean} [readonly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @attr {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @attr {number} [value=50] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n *\n * @prop {string | null} [name=null] - The name of this element that is associated with form submission\n * @prop {boolean} [disabled=false] - Represents whether a user can make changes to this element; if true, the value of this element will be excluded from the form submission\n * @prop {boolean} [readOnly=false] - Represents whether a user can make changes to this element; the value of this element will still be included in the form submission\n * @prop {boolean} [autofocus=false] - If true, this element will be focused when connected to the document\n * @prop {number} [valueAsNumber=50] - Returns the value of the element, interpreted as one of the following, in order: A number, NaN if conversion is impossible\n * @prop {string} [value='50'] - Represents the value of the input. Can be set to a default value, and will reflect the value provided by the user when interactive with the control\n * @prop {number} [progress=50] - Determines visual placement of the slider thumb along the line\n *\n * @cssprop [--zui-slider-thumb-size=1.875rem (30px)] - Point of contact to grab and slide to change value\n *\n * @event {CustomEvent} change - Fires when value changes, details contain `value`\n */\nexport class ZuiSlider extends ZuiFormAssociatedElement {\n protected get _formControlSelector() {\n return 'input';\n }\n\n protected get _formValue() {\n return this.value;\n }\n\n protected formResetCallback() {\n this.value = this.#defaultValue;\n }\n\n #defaultValue = `${DEFAULT_MAX / 2}`;\n\n #value = `${DEFAULT_MAX / 2}`;\n\n @property()\n get value() {\n return this.#value;\n }\n\n set value(val) {\n const oldVal = this.#value;\n val = this._ensureValidValue(val);\n this.#value = val;\n this._setFormValue(this.#value);\n this.requestUpdate('value', oldVal);\n }\n\n get valueAsNumber() {\n return parseFloat(this.#value);\n }\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number }) min = 0;\n\n /**\n * Represents the maximum permitted value\n */\n @property({ type: Number, attribute: 'max' }) max = 100;\n\n /**\n * Represents the stepping interval, used both for user interface and validation purposes\n */\n @property({ type: Number }) step = 0;\n\n /**\n * Represents that this control must be filled in for form submission\n */\n @property({ type: Boolean, attribute: 'no-text' }) noText = false;\n\n get progress() {\n return ((this.valueAsNumber - this.min) / (this.max - this.min)) * 100;\n }\n\n static get styles() {\n return [super.styles, style];\n }\n\n connectedCallback() {\n super.connectedCallback();\n\n // we want to go a little faster than LitElement and behave more like native HTML Form Associated Elements\n let value = this.getAttribute('value') ?? this.value;\n const max = this.getAttribute('max') ?? this.max;\n const min = this.getAttribute('min') ?? this.min;\n\n value = this._ensureValidValue(value, min, max);\n\n this.#defaultValue = value;\n this._setFormValue(value.toString());\n }\n\n render() {\n const progressColor = this.disabled ? 'var(--zui-gray)' : 'var(--zui-blue)';\n const styles = {\n background: `linear-gradient(to right, ${progressColor} 0%, ${progressColor} ${this.progress}%, var(--zui-gray-200) ${this.progress}%, var(--zui-gray-200) 100%)`,\n };\n return html`<input\n style=${styleMap(styles)}\n type=\"range\"\n .value=\"${this.value}\"\n .min=\"${this.min}\"\n .max=\"${this.max}\"\n .step=\"${this.step}\"\n ?disabled=\"${this.disabled}\"\n @input=\"${this._onInput}\"\n @change=\"${this._onChange}\"\n />${this._renderText()}`;\n }\n\n private _renderText() {\n if (this.noText) {\n return html``;\n }\n const thumbOffset = `var(--zui-slider-thumb-size) * ${this.progress / 100}`;\n const styles = {\n left: `calc(${this.progress}% - ${thumbOffset} + 0.125rem)`,\n };\n return html`<span style=${styleMap(styles)}>${this.value}</span>`;\n }\n\n private _onInput(e: Event) {\n this.value = (e.target as HTMLInputElement).value;\n }\n\n private _onChange() {\n this.dispatchEvent(new CustomEvent('change', { detail: this.value, bubbles: true }));\n }\n\n private _ensureValidValue(value: string | number, min?: number | string | null, max?: number | string | null) {\n if (value === '') {\n return value;\n }\n min = min ?? this.min;\n max = max ?? this.max;\n\n if (typeof value === 'string') {\n value = parseFloat(value);\n }\n if (typeof min === 'string') {\n min = parseFloat(min);\n }\n if (typeof max === 'string') {\n max = parseFloat(max);\n }\n\n if (value < min) {\n value = min;\n } else if (value > max) {\n value = max;\n }\n\n return value.toString();\n }\n}\n\nwindow.customElements.define('zui-slider', ZuiSlider);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'zui-slider': ZuiSlider;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zywave/zui-slider",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.1.0-pre.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zywave/zui-base": "^4.
|
|
24
|
+
"@zywave/zui-base": "^4.2.0-pre.0"
|
|
25
25
|
},
|
|
26
26
|
"customElements": "dist/custom-elements.json",
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1d65fd119122e053cfb26ec6779084a5a61657c5"
|
|
28
28
|
}
|
package/test/zui-slider.test.ts
CHANGED
|
@@ -5,8 +5,6 @@ import { ZuiSlider } from '@zywave/zui-slider';
|
|
|
5
5
|
import { assert } from '@esm-bundle/chai';
|
|
6
6
|
import { buildForm } from '../../../../test/src/util/form-helpers';
|
|
7
7
|
import { randString, randNumber } from '../../../../test/src/util/helpers';
|
|
8
|
-
import { conditionalTest } from '../../../../test/src/util/mocha-helpers';
|
|
9
|
-
import { SUPPORTS_FORMDATA_EVENT } from '@zywave/zui-base';
|
|
10
8
|
import { faceTests } from '../../../../test/src/util/face-tests';
|
|
11
9
|
|
|
12
10
|
suite('zui-slider', () => {
|
|
@@ -39,7 +37,7 @@ suite('zui-slider', () => {
|
|
|
39
37
|
assert.equal(element.disabled, false);
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
test('init slider associates with form properly', () => {
|
|
43
41
|
const value = randNumber(50);
|
|
44
42
|
const name = randString();
|
|
45
43
|
element.setAttribute('name', name);
|
|
@@ -50,23 +48,19 @@ suite('zui-slider', () => {
|
|
|
50
48
|
assert.equal(formVal, value.toString());
|
|
51
49
|
});
|
|
52
50
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
()
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
element.setAttribute('name', name);
|
|
61
|
-
element.setAttribute('max', max.toString());
|
|
62
|
-
element.setAttribute('value', val.toString());
|
|
51
|
+
test('init slider with max and value overrides associates with form properly', () => {
|
|
52
|
+
const max = randNumber();
|
|
53
|
+
const val = max + 1;
|
|
54
|
+
const name = randString();
|
|
55
|
+
element.setAttribute('name', name);
|
|
56
|
+
element.setAttribute('max', max.toString());
|
|
57
|
+
element.setAttribute('value', val.toString());
|
|
63
58
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
59
|
+
const formData = new FormData(form);
|
|
60
|
+
const formVal = formData.get(name);
|
|
61
|
+
assert.exists(formVal);
|
|
62
|
+
assert.equal(formVal, max.toString());
|
|
63
|
+
});
|
|
70
64
|
});
|
|
71
65
|
|
|
72
66
|
faceTests<ZuiSlider>('zui-slider', {
|