@mgdis/mg-components 5.1.0 → 5.2.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/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mg-badge_27.cjs.entry.js +354 -236
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
- package/dist/collection/components/atoms/mg-button/mg-button.js +3 -3
- package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
- package/dist/collection/components/molecules/inputs/MgInput.js +3 -11
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +41 -20
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +50 -39
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +42 -33
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +36 -17
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +35 -14
- package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +2 -3
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +28 -6
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +36 -17
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +38 -19
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +25 -6
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +37 -18
- package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +73 -27
- package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +6 -6
- package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
- package/dist/collection/components/molecules/mg-modal/mg-modal.js +0 -4
- package/dist/collection/utils/unit.test.utils.js +51 -0
- package/dist/collection/variables.css +6 -6
- package/dist/components/MgInput.js +4 -12
- package/dist/components/mg-badge2.js +1 -1
- package/dist/components/mg-button2.js +3 -3
- package/dist/components/mg-form.js +67 -26
- package/dist/components/mg-input-checkbox.js +36 -21
- package/dist/components/mg-input-date.js +44 -39
- package/dist/components/mg-input-numeric.js +37 -34
- package/dist/components/mg-input-password.js +32 -19
- package/dist/components/mg-input-radio.js +30 -15
- package/dist/components/mg-input-select2.js +32 -19
- package/dist/components/mg-input-text2.js +34 -21
- package/dist/components/mg-input-textarea.js +32 -19
- package/dist/components/mg-input-toggle.js +1 -1
- package/dist/components/mg-message.js +1 -1
- package/dist/components/mg-modal.js +0 -4
- package/dist/components/mg-tag.js +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mg-badge_27.entry.js +354 -236
- package/dist/esm/mg-components.js +1 -1
- package/dist/mg-components/mg-components.css +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/p-b2b07c3f.entry.js +1 -0
- package/dist/mg-components/variables.css +6 -6
- package/dist/types/components/atoms/mg-button/mg-button.d.ts +2 -2
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +10 -8
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +3 -8
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +3 -8
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +4 -3
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +4 -2
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +4 -3
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +5 -4
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -3
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +21 -1
- package/dist/types/components/molecules/mg-message/mg-message.d.ts +3 -0
- package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +3 -0
- package/package.json +7 -8
- package/dist/collection/utils/test.utils.js +0 -38
- package/dist/mg-components/p-e131701a.entry.js +0 -1
- package/dist/types/utils/test.utils.d.ts +0 -17
|
@@ -102,7 +102,7 @@ const MgBadge = class {
|
|
|
102
102
|
/************
|
|
103
103
|
* Internal *
|
|
104
104
|
************/
|
|
105
|
-
//
|
|
105
|
+
// Classes
|
|
106
106
|
this.classOutline = `mg-badge--outline`;
|
|
107
107
|
/**
|
|
108
108
|
* Define button variant
|
|
@@ -229,7 +229,7 @@ const MgButton = class {
|
|
|
229
229
|
}
|
|
230
230
|
};
|
|
231
231
|
/**
|
|
232
|
-
* Handle
|
|
232
|
+
* Handle onKeydown event
|
|
233
233
|
*
|
|
234
234
|
* @param {KeyboardEvent} event keyboard event
|
|
235
235
|
* @returns {void}
|
|
@@ -244,7 +244,7 @@ const MgButton = class {
|
|
|
244
244
|
}
|
|
245
245
|
};
|
|
246
246
|
/**
|
|
247
|
-
* Handle
|
|
247
|
+
* Handle onKeyup event
|
|
248
248
|
*
|
|
249
249
|
* @param {KeyboardEvent} event keyboard event
|
|
250
250
|
* @returns {void}
|
|
@@ -327,7 +327,7 @@ const MgButton = class {
|
|
|
327
327
|
* @returns {HTMLElement} html element
|
|
328
328
|
*/
|
|
329
329
|
render() {
|
|
330
|
-
return (h(Host, { role: "button", tabIndex: this.disabled ? -1 : 0, type: this.type, form: this.form, "full-width": this.fullWidth, "aria-label": this.label, "aria-disabled": this.disabled !== undefined && this.disabled.toString(), onClick: this.handleClick,
|
|
330
|
+
return (h(Host, { role: "button", tabIndex: this.disabled ? -1 : 0, type: this.type, form: this.form, "full-width": this.fullWidth, "aria-label": this.label, "aria-disabled": this.disabled !== undefined && this.disabled.toString(), onClick: this.handleClick, onKeyup: this.handleKeyup, onKeydown: this.handleKeydown }, h("div", { class: this.classList.join(), id: this.identifier }, this.loading && h("mg-icon", { icon: "loader", spin: true }), h("div", { class: "mg-button__content" }, h("slot", null)))));
|
|
331
331
|
}
|
|
332
332
|
get element() { return getElement(this); }
|
|
333
333
|
static get watchers() { return {
|
|
@@ -646,6 +646,8 @@ const MgForm = class {
|
|
|
646
646
|
registerInstance(this, hostRef);
|
|
647
647
|
this.formValid = createEvent(this, "form-valid", 7);
|
|
648
648
|
this.formSubmit = createEvent(this, "form-submit", 7);
|
|
649
|
+
// Classes
|
|
650
|
+
this.classAllRequired = 'mg-form--all-required';
|
|
649
651
|
/**
|
|
650
652
|
* Identifier is used for the element ID (id is a reserved prop in Stencil.js)
|
|
651
653
|
* If not set, it will be created.
|
|
@@ -675,17 +677,24 @@ const MgForm = class {
|
|
|
675
677
|
* @returns {void}
|
|
676
678
|
*/
|
|
677
679
|
this.setRequiredMessage = () => {
|
|
678
|
-
//
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
//
|
|
682
|
-
if
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
680
|
+
// init required message
|
|
681
|
+
this.requiredMessage = null;
|
|
682
|
+
this.classList.delete(this.classAllRequired);
|
|
683
|
+
// If the form is disabled or readonly none of them are required
|
|
684
|
+
// Check if all fields are not editable (readonly or disabled)
|
|
685
|
+
if (!this.disabled && !this.readonly && !this.mgInputs.every(input => input.disabled || input.readonly)) {
|
|
686
|
+
// Get required fields
|
|
687
|
+
const requiredInputs = this.mgInputs.filter(input => input.required && !input.disabled && !input.readonly);
|
|
688
|
+
// All fields are required
|
|
689
|
+
// mg-input-toggle can not be required
|
|
690
|
+
if (requiredInputs.length > 0 && requiredInputs.length === this.mgInputs.filter(input => input.nodeName !== 'MG-INPUT-TOGGLE').length) {
|
|
691
|
+
this.requiredMessage = this.messages.form.allRequired;
|
|
692
|
+
this.classList.add(this.classAllRequired);
|
|
693
|
+
}
|
|
694
|
+
// Some fields are required
|
|
695
|
+
else if (requiredInputs.length > 0) {
|
|
696
|
+
this.requiredMessage = this.messages.form.required;
|
|
697
|
+
}
|
|
689
698
|
}
|
|
690
699
|
};
|
|
691
700
|
/**
|
|
@@ -694,15 +703,46 @@ const MgForm = class {
|
|
|
694
703
|
* @returns {void}
|
|
695
704
|
*/
|
|
696
705
|
this.checkValidity = () => {
|
|
697
|
-
|
|
698
|
-
this.
|
|
699
|
-
this.
|
|
700
|
-
this.
|
|
706
|
+
// Update required on input event
|
|
707
|
+
this.setRequiredMessage();
|
|
708
|
+
this.valid = !this.mgInputs.some(input => input.invalid);
|
|
709
|
+
this.invalid = !this.valid;
|
|
710
|
+
// We need to send valid event if it is the same value
|
|
711
|
+
this.formValid.emit(this.valid);
|
|
701
712
|
};
|
|
713
|
+
/**
|
|
714
|
+
* Handle Form Submit
|
|
715
|
+
*
|
|
716
|
+
* @param {SubmitEvent} event submit event
|
|
717
|
+
* @returns {void}
|
|
718
|
+
*/
|
|
702
719
|
this.handleFormSubmit = (event) => {
|
|
703
720
|
event.preventDefault();
|
|
704
721
|
this.formSubmit.emit();
|
|
705
722
|
};
|
|
723
|
+
/**
|
|
724
|
+
* Set mgInputs
|
|
725
|
+
*
|
|
726
|
+
* @returns {void}
|
|
727
|
+
*/
|
|
728
|
+
this.setMgInputs = () => {
|
|
729
|
+
// Get slotted mgInputs
|
|
730
|
+
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
731
|
+
// Set inputs readonly or disabled based on form configuration
|
|
732
|
+
// Othewise listen to events
|
|
733
|
+
this.mgInputs.map(input => {
|
|
734
|
+
if (this.readonly)
|
|
735
|
+
input.readonly = true;
|
|
736
|
+
else if (this.disabled)
|
|
737
|
+
input.disabled = true;
|
|
738
|
+
else
|
|
739
|
+
input.addEventListener('input-valid', this.checkValidity);
|
|
740
|
+
});
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
handleAttributeChange() {
|
|
744
|
+
this.setMgInputs();
|
|
745
|
+
this.setRequiredMessage();
|
|
706
746
|
}
|
|
707
747
|
/**
|
|
708
748
|
* Public method to display errors
|
|
@@ -728,26 +768,18 @@ const MgForm = class {
|
|
|
728
768
|
componentWillLoad() {
|
|
729
769
|
// Get locales
|
|
730
770
|
this.messages = initLocales(this.element).messages;
|
|
731
|
-
// Get slotted mgInputs
|
|
732
|
-
this.mgInputs = Array.from(this.element.querySelectorAll('*')).filter((node) => node.nodeName.startsWith('MG-INPUT-'));
|
|
733
771
|
// Get slotted mgButtons
|
|
734
|
-
this.mgButtons = Array.from(this.element.querySelectorAll('
|
|
772
|
+
this.mgButtons = Array.from(this.element.querySelectorAll('mg-button'));
|
|
735
773
|
// Set button form identifier
|
|
736
774
|
this.mgButtons.forEach(mgButton => {
|
|
737
775
|
mgButton.setAttribute('form', this.identifier);
|
|
738
776
|
});
|
|
777
|
+
// Set mgInputs
|
|
778
|
+
this.setMgInputs();
|
|
739
779
|
// Define required message
|
|
740
780
|
this.setRequiredMessage();
|
|
741
781
|
// Check validity when slotted mgInputs are ready
|
|
742
782
|
Promise.all(this.mgInputs.map(async (input) => {
|
|
743
|
-
// Set inputs readonly or disabled based on form configuration
|
|
744
|
-
// Othewise listen to events
|
|
745
|
-
if (this.readonly)
|
|
746
|
-
input.readonly = true;
|
|
747
|
-
else if (this.disabled)
|
|
748
|
-
input.disabled = true;
|
|
749
|
-
else
|
|
750
|
-
input.addEventListener('input-valid', this.checkValidity);
|
|
751
783
|
try {
|
|
752
784
|
await input.componentOnReady();
|
|
753
785
|
}
|
|
@@ -770,6 +802,10 @@ const MgForm = class {
|
|
|
770
802
|
});
|
|
771
803
|
}
|
|
772
804
|
});
|
|
805
|
+
// Update mgInputs when mgForm content change
|
|
806
|
+
new MutationObserver(() => {
|
|
807
|
+
this.setMgInputs();
|
|
808
|
+
}).observe(this.element, { childList: true });
|
|
773
809
|
}
|
|
774
810
|
/**
|
|
775
811
|
* Render
|
|
@@ -780,6 +816,10 @@ const MgForm = class {
|
|
|
780
816
|
return (h("form", { class: this.classList.join(), id: this.identifier, name: this.name, ref: el => (this.form = el), onSubmit: this.handleFormSubmit }, this.requiredMessage && h("p", { innerHTML: this.requiredMessage }), h("slot", null), !this.readonly && !this.disabled && h("slot", { name: "actions" })));
|
|
781
817
|
}
|
|
782
818
|
get element() { return getElement(this); }
|
|
819
|
+
static get watchers() { return {
|
|
820
|
+
"readonly": ["handleAttributeChange"],
|
|
821
|
+
"disabled": ["handleAttributeChange"]
|
|
822
|
+
}; }
|
|
783
823
|
};
|
|
784
824
|
MgForm.style = mgFormCss;
|
|
785
825
|
|
|
@@ -1168,15 +1208,6 @@ const MgInput = (props, children, utils) => {
|
|
|
1168
1208
|
if (typeof props.errorMessage === 'string' && props.errorMessage !== '') {
|
|
1169
1209
|
ariaDescribedbyIDs.add(helpTextErrorId);
|
|
1170
1210
|
}
|
|
1171
|
-
/**
|
|
1172
|
-
* Update input(s) in children
|
|
1173
|
-
*/
|
|
1174
|
-
if (props.readonly) {
|
|
1175
|
-
children = children.filter(child => child.$name$ === 'append-input');
|
|
1176
|
-
}
|
|
1177
|
-
else {
|
|
1178
|
-
children = applyAriadescribedBy(children, ariaDescribedbyIDs, utils);
|
|
1179
|
-
}
|
|
1180
1211
|
/**
|
|
1181
1212
|
* Return template
|
|
1182
1213
|
*
|
|
@@ -1202,19 +1233,20 @@ const MgInput = (props, children, utils) => {
|
|
|
1202
1233
|
h("mg-icon", { icon: "info-circle" })));
|
|
1203
1234
|
/**
|
|
1204
1235
|
* Get input title (label) node
|
|
1236
|
+
* Display asterisk only if not disabled and not readonly
|
|
1205
1237
|
*
|
|
1206
1238
|
* @returns {VNode[]} mg-input-title
|
|
1207
1239
|
*/
|
|
1208
|
-
const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled, "is-legend": props.isFieldset }, props.label));
|
|
1240
|
+
const getInputTitle = () => (h("mg-input-title", { identifier: props.identifier, class: props.labelHide ? 'sr-only' : undefined, required: props.required && !props.disabled && !props.readonly, "is-legend": props.isFieldset }, props.label));
|
|
1209
1241
|
return (h(TagName, { class: props.classList.join() },
|
|
1210
1242
|
props.labelOnTop ? (h("div", { class: "mg-input__title" },
|
|
1211
1243
|
getInputTitle(),
|
|
1212
1244
|
!props.readonly && props.tooltip && getTooltip())) : (getInputTitle()),
|
|
1213
1245
|
props.readonly ? (h("div", { class: "mg-input__input-container" },
|
|
1214
1246
|
h("strong", null, props.readonlyValue || props.value),
|
|
1215
|
-
children)) : (h("div", { class: "mg-input__input-container" },
|
|
1247
|
+
children.filter(child => child.$name$ === 'append-input'))) : (h("div", { class: "mg-input__input-container" },
|
|
1216
1248
|
h("div", { class: { 'mg-input__input': true, 'mg-input__input--has-error': props.errorMessage !== undefined } },
|
|
1217
|
-
children,
|
|
1249
|
+
applyAriadescribedBy(children, ariaDescribedbyIDs, utils),
|
|
1218
1250
|
!props.labelOnTop && props.tooltip && getTooltip()),
|
|
1219
1251
|
props.helpText && h("div", { id: helpTextId, class: "mg-input__help-text", innerHTML: props.helpText }),
|
|
1220
1252
|
props.errorMessage && !props.readonly && !props.disabled && (h("div", { id: helpTextErrorId, class: "mg-input__error", innerHTML: props.errorMessage, "aria-live": "assertive" }))))));
|
|
@@ -1239,6 +1271,8 @@ const MgInputCheckbox = class {
|
|
|
1239
1271
|
************/
|
|
1240
1272
|
// HTML selector
|
|
1241
1273
|
this.inputs = [];
|
|
1274
|
+
// hasDisplayedError (triggered by blur event)
|
|
1275
|
+
this.hasDisplayedError = false;
|
|
1242
1276
|
/**
|
|
1243
1277
|
* Input name
|
|
1244
1278
|
* If not set the value equals the identifier
|
|
@@ -1293,25 +1327,27 @@ const MgInputCheckbox = class {
|
|
|
1293
1327
|
this.handleBlur = () => {
|
|
1294
1328
|
// Check validity
|
|
1295
1329
|
this.checkValidity();
|
|
1296
|
-
this.
|
|
1330
|
+
this.setErrorMessage();
|
|
1297
1331
|
};
|
|
1332
|
+
/**
|
|
1333
|
+
* get invalid element
|
|
1334
|
+
*
|
|
1335
|
+
* @returns {HTMLInputElement} element
|
|
1336
|
+
*/
|
|
1337
|
+
this.getInvalidElement = () => this.inputs.find((input) => input !== null && !input.disabled && !input.checkValidity());
|
|
1298
1338
|
/**
|
|
1299
1339
|
* Check if input is valid
|
|
1300
1340
|
*/
|
|
1301
1341
|
this.checkValidity = () => {
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
this.invalid = !validity;
|
|
1307
|
-
//Send event
|
|
1308
|
-
this.inputValid.emit(validity);
|
|
1309
|
-
}
|
|
1342
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
1343
|
+
this.invalid = !this.valid;
|
|
1344
|
+
// We need to send valid event even if it is the same value
|
|
1345
|
+
this.inputValid.emit(this.valid);
|
|
1310
1346
|
};
|
|
1311
1347
|
/**
|
|
1312
|
-
*
|
|
1348
|
+
* Set input error message
|
|
1313
1349
|
*/
|
|
1314
|
-
this.
|
|
1350
|
+
this.setErrorMessage = () => {
|
|
1315
1351
|
const invalidElement = this.getInvalidElement();
|
|
1316
1352
|
// Set error message
|
|
1317
1353
|
this.errorMessage = undefined;
|
|
@@ -1319,12 +1355,6 @@ const MgInputCheckbox = class {
|
|
|
1319
1355
|
this.errorMessage = this.messages.errors.required;
|
|
1320
1356
|
}
|
|
1321
1357
|
};
|
|
1322
|
-
/**
|
|
1323
|
-
* get invalid element
|
|
1324
|
-
*
|
|
1325
|
-
* @returns {HTMLInputElement} element
|
|
1326
|
-
*/
|
|
1327
|
-
this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
|
|
1328
1358
|
}
|
|
1329
1359
|
validateValue(newValue) {
|
|
1330
1360
|
if (newValue && newValue.every(item => isCheckboxItem(item))) {
|
|
@@ -1340,6 +1370,16 @@ const MgInputCheckbox = class {
|
|
|
1340
1370
|
throw new Error('<mg-input-checkbox> prop "value" is required and all values must be the same type, CheckboxItem.');
|
|
1341
1371
|
}
|
|
1342
1372
|
}
|
|
1373
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1374
|
+
this.inputs.forEach(input => {
|
|
1375
|
+
input[prop] = newValue;
|
|
1376
|
+
});
|
|
1377
|
+
this.checkValidity();
|
|
1378
|
+
if (this.hasDisplayedError) {
|
|
1379
|
+
this.setErrorMessage();
|
|
1380
|
+
this.hasDisplayedError = false;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1343
1383
|
/**
|
|
1344
1384
|
* Public method to display errors
|
|
1345
1385
|
*
|
|
@@ -1347,7 +1387,8 @@ const MgInputCheckbox = class {
|
|
|
1347
1387
|
*/
|
|
1348
1388
|
async displayError() {
|
|
1349
1389
|
this.checkValidity();
|
|
1350
|
-
this.
|
|
1390
|
+
this.setErrorMessage();
|
|
1391
|
+
this.hasDisplayedError = this.invalid;
|
|
1351
1392
|
}
|
|
1352
1393
|
/*************
|
|
1353
1394
|
* Lifecycle *
|
|
@@ -1375,15 +1416,21 @@ const MgInputCheckbox = class {
|
|
|
1375
1416
|
* @returns {HTMLElement} HTML Element
|
|
1376
1417
|
*/
|
|
1377
1418
|
render() {
|
|
1378
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly
|
|
1419
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: !this.readonly ? this.required : undefined, readonly: undefined, mgWidth: undefined, disabled: this.disabled, value: this.value && this.value.toString(), readonlyValue: undefined, tooltip: !this.readonly ? this.tooltip : undefined, helpText: !this.readonly ? this.helpText : undefined, errorMessage: !this.readonly ? this.errorMessage : undefined, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.checkboxItems
|
|
1379
1420
|
.filter(item => {
|
|
1380
1421
|
return !this.readonly || item.value;
|
|
1381
1422
|
})
|
|
1382
|
-
.map(input => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
1423
|
+
.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "checkbox", id: input.id, name: this.identifier, value: input.value && input.value.toString(), checked: Boolean(input.value), disabled: this.readonly || this.disabled || input.disabled, required: this.required, indeterminate: input.value === null, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
1424
|
+
if (el !== null)
|
|
1425
|
+
this.inputs[index] = el;
|
|
1426
|
+
} }), h("label", { htmlFor: input.id }, input.title)))))));
|
|
1383
1427
|
}
|
|
1384
1428
|
get element() { return getElement(this); }
|
|
1385
1429
|
static get watchers() { return {
|
|
1386
|
-
"value": ["validateValue"]
|
|
1430
|
+
"value": ["validateValue"],
|
|
1431
|
+
"required": ["handleValidityChange"],
|
|
1432
|
+
"readonly": ["handleValidityChange"],
|
|
1433
|
+
"disabled": ["handleValidityChange"]
|
|
1387
1434
|
}; }
|
|
1388
1435
|
};
|
|
1389
1436
|
MgInputCheckbox.style = mgInputCheckboxCss;
|
|
@@ -1442,8 +1489,8 @@ const MgInputDate = class {
|
|
|
1442
1489
|
registerInstance(this, hostRef);
|
|
1443
1490
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1444
1491
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1445
|
-
//
|
|
1446
|
-
this.
|
|
1492
|
+
// hasDisplayedError (triggered by blur event)
|
|
1493
|
+
this.hasDisplayedError = false;
|
|
1447
1494
|
/**
|
|
1448
1495
|
* Input name
|
|
1449
1496
|
* If not set the value equals the identifier
|
|
@@ -1474,8 +1521,8 @@ const MgInputDate = class {
|
|
|
1474
1521
|
*/
|
|
1475
1522
|
this.handleInput = () => {
|
|
1476
1523
|
this.checkValidity();
|
|
1477
|
-
if (this.
|
|
1478
|
-
this.
|
|
1524
|
+
if (this.hasDisplayedError) {
|
|
1525
|
+
this.setErrorMessage();
|
|
1479
1526
|
}
|
|
1480
1527
|
this.value = this.input.value;
|
|
1481
1528
|
};
|
|
@@ -1489,14 +1536,11 @@ const MgInputDate = class {
|
|
|
1489
1536
|
* Check if input is valid
|
|
1490
1537
|
*/
|
|
1491
1538
|
this.checkValidity = () => {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
//Send event
|
|
1498
|
-
this.inputValid.emit(validity);
|
|
1499
|
-
}
|
|
1539
|
+
var _a;
|
|
1540
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
1541
|
+
this.invalid = !this.valid;
|
|
1542
|
+
// We need to send valid event even if it is the same value
|
|
1543
|
+
this.inputValid.emit(this.valid);
|
|
1500
1544
|
};
|
|
1501
1545
|
/**
|
|
1502
1546
|
* get input error code
|
|
@@ -1525,48 +1569,50 @@ const MgInputDate = class {
|
|
|
1525
1569
|
return inputError;
|
|
1526
1570
|
};
|
|
1527
1571
|
/**
|
|
1528
|
-
*
|
|
1572
|
+
* Check input errors
|
|
1529
1573
|
*
|
|
1530
1574
|
* @returns {void}
|
|
1531
1575
|
*/
|
|
1532
1576
|
this.setErrorMessage = () => {
|
|
1533
1577
|
var _a;
|
|
1534
|
-
const inputError = this.getInputError();
|
|
1535
|
-
// required
|
|
1536
|
-
if (inputError === InputError$1.REQUIRED) {
|
|
1537
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1538
|
-
}
|
|
1539
|
-
// min, max & minMax
|
|
1540
|
-
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1541
|
-
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1542
|
-
}
|
|
1543
|
-
// wrong date format
|
|
1544
|
-
// element.validity.badInput is default error message
|
|
1545
|
-
else {
|
|
1546
|
-
this.errorMessage = this.messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min, this.locale) : localeDate('1900-01-01', this.locale));
|
|
1547
|
-
}
|
|
1548
|
-
};
|
|
1549
|
-
/**
|
|
1550
|
-
* Check input errors
|
|
1551
|
-
*
|
|
1552
|
-
* @returns {void}
|
|
1553
|
-
*/
|
|
1554
|
-
this.checkError = () => {
|
|
1555
1578
|
// Set error message
|
|
1556
1579
|
this.errorMessage = undefined;
|
|
1557
1580
|
if (!this.valid) {
|
|
1558
|
-
this.
|
|
1581
|
+
const inputError = this.getInputError();
|
|
1582
|
+
// required
|
|
1583
|
+
if (inputError === InputError$1.REQUIRED) {
|
|
1584
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1585
|
+
}
|
|
1586
|
+
// min, max & minMax
|
|
1587
|
+
else if ([InputError$1.MIN, InputError$1.MAX, InputError$1.MINMAX].includes(inputError)) {
|
|
1588
|
+
this.errorMessage = this.messages.errors.date[inputError].replace('{min}', localeDate(this.min, this.locale)).replace('{max}', localeDate(this.max, this.locale));
|
|
1589
|
+
}
|
|
1590
|
+
// wrong date format
|
|
1591
|
+
// element.validity.badInput is default error message
|
|
1592
|
+
else {
|
|
1593
|
+
this.errorMessage = this.messages.errors.date.badInput.replace('{min}', ((_a = this.min) === null || _a === void 0 ? void 0 : _a.length) > 0 ? localeDate(this.min, this.locale) : localeDate('1900-01-01', this.locale));
|
|
1594
|
+
}
|
|
1559
1595
|
}
|
|
1560
1596
|
};
|
|
1561
1597
|
}
|
|
1562
1598
|
validateValue(newValue) {
|
|
1563
|
-
if (newValue !== undefined && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1599
|
+
if (newValue !== undefined && newValue !== null && (typeof newValue !== 'string' || !dateRegExp.test(newValue))) {
|
|
1564
1600
|
throw new Error("<mg-input-date> props 'value' doesn't match pattern: yyyy-mm-dd");
|
|
1565
1601
|
}
|
|
1566
1602
|
else {
|
|
1567
1603
|
this.valueChange.emit(this.value);
|
|
1568
1604
|
}
|
|
1569
1605
|
}
|
|
1606
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1607
|
+
if (this.input !== undefined) {
|
|
1608
|
+
this.input[prop] = newValue;
|
|
1609
|
+
this.checkValidity();
|
|
1610
|
+
if (this.hasDisplayedError) {
|
|
1611
|
+
this.setErrorMessage();
|
|
1612
|
+
this.hasDisplayedError = false;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1570
1616
|
validateMinMax(newValue) {
|
|
1571
1617
|
if ((newValue === null || newValue === void 0 ? void 0 : newValue.length) === 0 || ((newValue === null || newValue === void 0 ? void 0 : newValue.length) > 0 && !(typeof newValue === 'string' && dateRegExp.test(newValue)))) {
|
|
1572
1618
|
throw new Error("<mg-input-date> props 'min/max' doesn't match pattern: yyyy-mm-dd");
|
|
@@ -1579,8 +1625,8 @@ const MgInputDate = class {
|
|
|
1579
1625
|
*/
|
|
1580
1626
|
async displayError() {
|
|
1581
1627
|
this.checkValidity();
|
|
1582
|
-
this.
|
|
1583
|
-
this.
|
|
1628
|
+
this.setErrorMessage();
|
|
1629
|
+
this.hasDisplayedError = this.invalid;
|
|
1584
1630
|
}
|
|
1585
1631
|
/*************
|
|
1586
1632
|
* Lifecycle *
|
|
@@ -1612,11 +1658,17 @@ const MgInputDate = class {
|
|
|
1612
1658
|
* @returns {HTMLElement} HTML Element
|
|
1613
1659
|
*/
|
|
1614
1660
|
render() {
|
|
1615
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value, this.locale), tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el =>
|
|
1661
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: undefined, disabled: this.disabled, value: this.value, readonlyValue: localeDate(this.value, this.locale), tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "date", class: "mg-input__box", min: this.min, max: this.max, value: this.value, id: this.identifier, name: this.name, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, pattern: "[0-9]{4}-[0-9]{2}-[0-9]{2}", ref: el => {
|
|
1662
|
+
if (el !== null)
|
|
1663
|
+
this.input = el;
|
|
1664
|
+
} })));
|
|
1616
1665
|
}
|
|
1617
1666
|
get element() { return getElement(this); }
|
|
1618
1667
|
static get watchers() { return {
|
|
1619
1668
|
"value": ["validateValue"],
|
|
1669
|
+
"required": ["handleValidityChange"],
|
|
1670
|
+
"readonly": ["handleValidityChange"],
|
|
1671
|
+
"disabled": ["handleValidityChange"],
|
|
1620
1672
|
"min": ["validateMinMax"],
|
|
1621
1673
|
"max": ["validateMinMax"]
|
|
1622
1674
|
}; }
|
|
@@ -1635,15 +1687,15 @@ var InputError;
|
|
|
1635
1687
|
InputError["REQUIRED"] = "required";
|
|
1636
1688
|
})(InputError || (InputError = {}));
|
|
1637
1689
|
|
|
1638
|
-
const mgInputNumericCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{text-align:var(--mg-inputs-text-align, right)}";
|
|
1690
|
+
const mgInputNumericCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{text-align:var(--mg-inputs-text-align, right)}";
|
|
1639
1691
|
|
|
1640
1692
|
const MgInputNumeric = class {
|
|
1641
1693
|
constructor(hostRef) {
|
|
1642
1694
|
registerInstance(this, hostRef);
|
|
1643
1695
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1644
1696
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1645
|
-
//
|
|
1646
|
-
this.
|
|
1697
|
+
// hasDisplayedError (triggered by blur event)
|
|
1698
|
+
this.hasDisplayedError = false;
|
|
1647
1699
|
/**
|
|
1648
1700
|
* Input name
|
|
1649
1701
|
* If not set the value equals the identifier
|
|
@@ -1699,8 +1751,8 @@ const MgInputNumeric = class {
|
|
|
1699
1751
|
this.handleInput = () => {
|
|
1700
1752
|
// Check validity
|
|
1701
1753
|
this.checkValidity();
|
|
1702
|
-
if (this.
|
|
1703
|
-
this.
|
|
1754
|
+
if (this.hasDisplayedError) {
|
|
1755
|
+
this.setErrorMessage();
|
|
1704
1756
|
}
|
|
1705
1757
|
this.value = this.input.value;
|
|
1706
1758
|
};
|
|
@@ -1728,40 +1780,27 @@ const MgInputNumeric = class {
|
|
|
1728
1780
|
* @returns {void}
|
|
1729
1781
|
*/
|
|
1730
1782
|
this.checkValidity = () => {
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
this.invalid = !validity;
|
|
1736
|
-
//Send event
|
|
1737
|
-
this.inputValid.emit(validity);
|
|
1738
|
-
}
|
|
1783
|
+
this.valid = this.readonly || this.disabled || this.getInputError() === null;
|
|
1784
|
+
this.invalid = !this.valid;
|
|
1785
|
+
// We need to send valid event even if it is the same value
|
|
1786
|
+
this.inputValid.emit(this.valid);
|
|
1739
1787
|
};
|
|
1740
1788
|
/**
|
|
1741
|
-
* Set error message
|
|
1789
|
+
* Set input error message
|
|
1742
1790
|
*
|
|
1743
1791
|
* @returns {void}
|
|
1744
1792
|
*/
|
|
1745
1793
|
this.setErrorMessage = () => {
|
|
1746
|
-
const inputError = this.getInputError();
|
|
1747
|
-
if (inputError === InputError.REQUIRED) {
|
|
1748
|
-
this.errorMessage = this.messages.errors[inputError];
|
|
1749
|
-
}
|
|
1750
|
-
else {
|
|
1751
|
-
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1752
|
-
}
|
|
1753
|
-
};
|
|
1754
|
-
/**
|
|
1755
|
-
* Check input errors
|
|
1756
|
-
*
|
|
1757
|
-
* @returns {void}
|
|
1758
|
-
*/
|
|
1759
|
-
this.checkError = () => {
|
|
1760
1794
|
// Set error message
|
|
1761
1795
|
this.errorMessage = undefined;
|
|
1762
|
-
// Update class
|
|
1763
1796
|
if (!this.valid) {
|
|
1764
|
-
this.
|
|
1797
|
+
const inputError = this.getInputError();
|
|
1798
|
+
if (inputError === InputError.REQUIRED) {
|
|
1799
|
+
this.errorMessage = this.messages.errors[inputError];
|
|
1800
|
+
}
|
|
1801
|
+
else {
|
|
1802
|
+
this.errorMessage = this.messages.errors.numeric[inputError].replace('{min}', `${this.formatValue(this.min)}`).replace('{max}', `${this.formatValue(this.max)}`);
|
|
1803
|
+
}
|
|
1765
1804
|
}
|
|
1766
1805
|
};
|
|
1767
1806
|
/**
|
|
@@ -1771,7 +1810,7 @@ const MgInputNumeric = class {
|
|
|
1771
1810
|
*/
|
|
1772
1811
|
this.getInputError = () => {
|
|
1773
1812
|
let inputError = null;
|
|
1774
|
-
if (this.input === undefined)
|
|
1813
|
+
if (this.input === undefined || this.input === null)
|
|
1775
1814
|
return inputError;
|
|
1776
1815
|
// required
|
|
1777
1816
|
if (!this.input.checkValidity() && this.input.validity.valueMissing) {
|
|
@@ -1838,6 +1877,16 @@ const MgInputNumeric = class {
|
|
|
1838
1877
|
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
1839
1878
|
}
|
|
1840
1879
|
}
|
|
1880
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
1881
|
+
if (this.input !== undefined) {
|
|
1882
|
+
this.input[prop] = newValue;
|
|
1883
|
+
this.checkValidity();
|
|
1884
|
+
if (this.hasDisplayedError) {
|
|
1885
|
+
this.setErrorMessage();
|
|
1886
|
+
this.hasDisplayedError = false;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
}
|
|
1841
1890
|
validateType(newValue) {
|
|
1842
1891
|
if (!types.includes(newValue)) {
|
|
1843
1892
|
throw new Error(`<mg-input-numeric> prop "type" must be one of : ${types.join(', ')}`);
|
|
@@ -1860,8 +1909,8 @@ const MgInputNumeric = class {
|
|
|
1860
1909
|
*/
|
|
1861
1910
|
async displayError() {
|
|
1862
1911
|
this.checkValidity();
|
|
1863
|
-
this.
|
|
1864
|
-
this.
|
|
1912
|
+
this.setErrorMessage();
|
|
1913
|
+
this.hasDisplayedError = this.invalid;
|
|
1865
1914
|
}
|
|
1866
1915
|
/**
|
|
1867
1916
|
* Displayed value in input
|
|
@@ -1904,11 +1953,17 @@ const MgInputNumeric = class {
|
|
|
1904
1953
|
* @returns {HTMLElement} HTML Element
|
|
1905
1954
|
*/
|
|
1906
1955
|
render() {
|
|
1907
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
1956
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "text", class: "mg-input__box", value: this.displayValue(), id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
1957
|
+
if (el !== null)
|
|
1958
|
+
this.input = el;
|
|
1959
|
+
} }), h("slot", { name: "append-input" })));
|
|
1908
1960
|
}
|
|
1909
1961
|
get element() { return getElement(this); }
|
|
1910
1962
|
static get watchers() { return {
|
|
1911
1963
|
"value": ["validateValue"],
|
|
1964
|
+
"required": ["handleValidityChange"],
|
|
1965
|
+
"readonly": ["handleValidityChange"],
|
|
1966
|
+
"disabled": ["handleValidityChange"],
|
|
1912
1967
|
"type": ["validateType"],
|
|
1913
1968
|
"integerLength": ["validateIntegerLength"],
|
|
1914
1969
|
"decimalLength": ["validateDecimalLength"]
|
|
@@ -1916,15 +1971,15 @@ const MgInputNumeric = class {
|
|
|
1916
1971
|
};
|
|
1917
1972
|
MgInputNumeric.style = mgInputNumericCss;
|
|
1918
1973
|
|
|
1919
|
-
const mgInputPasswordCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}";
|
|
1974
|
+
const mgInputPasswordCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}";
|
|
1920
1975
|
|
|
1921
1976
|
const MgInputPassword = class {
|
|
1922
1977
|
constructor(hostRef) {
|
|
1923
1978
|
registerInstance(this, hostRef);
|
|
1924
1979
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
1925
1980
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1926
|
-
//
|
|
1927
|
-
this.
|
|
1981
|
+
// hasDisplayedError (triggered by blur event)
|
|
1982
|
+
this.hasDisplayedError = false;
|
|
1928
1983
|
/**
|
|
1929
1984
|
* Input name
|
|
1930
1985
|
* If not set the value equals the identifier
|
|
@@ -1959,8 +2014,8 @@ const MgInputPassword = class {
|
|
|
1959
2014
|
*/
|
|
1960
2015
|
this.handleInput = () => {
|
|
1961
2016
|
this.checkValidity();
|
|
1962
|
-
if (this.
|
|
1963
|
-
this.
|
|
2017
|
+
if (this.hasDisplayedError) {
|
|
2018
|
+
this.setErrorMessage();
|
|
1964
2019
|
}
|
|
1965
2020
|
this.value = this.input.value;
|
|
1966
2021
|
};
|
|
@@ -1974,19 +2029,16 @@ const MgInputPassword = class {
|
|
|
1974
2029
|
* Check if input is valid
|
|
1975
2030
|
*/
|
|
1976
2031
|
this.checkValidity = () => {
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
//Send event
|
|
1983
|
-
this.inputValid.emit(validity);
|
|
1984
|
-
}
|
|
2032
|
+
var _a;
|
|
2033
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2034
|
+
this.invalid = !this.valid;
|
|
2035
|
+
// We need to send valid event even if it is the same value
|
|
2036
|
+
this.inputValid.emit(this.valid);
|
|
1985
2037
|
};
|
|
1986
2038
|
/**
|
|
1987
|
-
*
|
|
2039
|
+
* Set input error message
|
|
1988
2040
|
*/
|
|
1989
|
-
this.
|
|
2041
|
+
this.setErrorMessage = () => {
|
|
1990
2042
|
// Set error message
|
|
1991
2043
|
this.errorMessage = undefined;
|
|
1992
2044
|
// required
|
|
@@ -1998,6 +2050,16 @@ const MgInputPassword = class {
|
|
|
1998
2050
|
handleValue(newValue) {
|
|
1999
2051
|
this.valueChange.emit(newValue);
|
|
2000
2052
|
}
|
|
2053
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2054
|
+
if (this.input !== undefined) {
|
|
2055
|
+
this.input[prop] = newValue;
|
|
2056
|
+
this.checkValidity();
|
|
2057
|
+
if (this.hasDisplayedError) {
|
|
2058
|
+
this.setErrorMessage();
|
|
2059
|
+
this.hasDisplayedError = false;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2001
2063
|
/**
|
|
2002
2064
|
* Public method to display errors
|
|
2003
2065
|
*
|
|
@@ -2005,8 +2067,8 @@ const MgInputPassword = class {
|
|
|
2005
2067
|
*/
|
|
2006
2068
|
async displayError() {
|
|
2007
2069
|
this.checkValidity();
|
|
2008
|
-
this.
|
|
2009
|
-
this.
|
|
2070
|
+
this.setErrorMessage();
|
|
2071
|
+
this.hasDisplayedError = this.invalid;
|
|
2010
2072
|
}
|
|
2011
2073
|
/*************
|
|
2012
2074
|
* Lifecycle *
|
|
@@ -2032,11 +2094,17 @@ const MgInputPassword = class {
|
|
|
2032
2094
|
* @returns {HTMLElement} HTML Element
|
|
2033
2095
|
*/
|
|
2034
2096
|
render() {
|
|
2035
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
2097
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.value !== undefined ? '•'.repeat(this.value.length) : undefined, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("input", { type: "password", class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
2098
|
+
if (el !== null)
|
|
2099
|
+
this.input = el;
|
|
2100
|
+
} })));
|
|
2036
2101
|
}
|
|
2037
2102
|
get element() { return getElement(this); }
|
|
2038
2103
|
static get watchers() { return {
|
|
2039
|
-
"value": ["handleValue"]
|
|
2104
|
+
"value": ["handleValue"],
|
|
2105
|
+
"required": ["handleValidityChange"],
|
|
2106
|
+
"readonly": ["handleValidityChange"],
|
|
2107
|
+
"disabled": ["handleValidityChange"]
|
|
2040
2108
|
}; }
|
|
2041
2109
|
};
|
|
2042
2110
|
MgInputPassword.style = mgInputPasswordCss;
|
|
@@ -2060,6 +2128,8 @@ const MgInputRadio = class {
|
|
|
2060
2128
|
************/
|
|
2061
2129
|
// HTML selector
|
|
2062
2130
|
this.inputs = [];
|
|
2131
|
+
// hasDisplayedError (triggered by blur event)
|
|
2132
|
+
this.hasDisplayedError = false;
|
|
2063
2133
|
/**
|
|
2064
2134
|
* Input name
|
|
2065
2135
|
* If not set the value equals the identifier
|
|
@@ -2110,7 +2180,7 @@ const MgInputRadio = class {
|
|
|
2110
2180
|
*/
|
|
2111
2181
|
this.handleBlur = () => {
|
|
2112
2182
|
this.checkValidity();
|
|
2113
|
-
this.
|
|
2183
|
+
this.setErrorMessage();
|
|
2114
2184
|
};
|
|
2115
2185
|
/**
|
|
2116
2186
|
* Check if input is valid
|
|
@@ -2118,21 +2188,17 @@ const MgInputRadio = class {
|
|
|
2118
2188
|
* @returns {void}
|
|
2119
2189
|
*/
|
|
2120
2190
|
this.checkValidity = () => {
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
this.invalid = !validity;
|
|
2126
|
-
//Send event
|
|
2127
|
-
this.inputValid.emit(validity);
|
|
2128
|
-
}
|
|
2191
|
+
this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
|
|
2192
|
+
this.invalid = !this.valid;
|
|
2193
|
+
// We need to send valid event even if it is the same value
|
|
2194
|
+
this.inputValid.emit(this.valid);
|
|
2129
2195
|
};
|
|
2130
2196
|
/**
|
|
2131
|
-
*
|
|
2197
|
+
* Set input error message
|
|
2132
2198
|
*
|
|
2133
2199
|
* @returns {void}
|
|
2134
2200
|
*/
|
|
2135
|
-
this.
|
|
2201
|
+
this.setErrorMessage = () => {
|
|
2136
2202
|
const invalidElement = this.getInvalidElement();
|
|
2137
2203
|
// Set error message
|
|
2138
2204
|
this.errorMessage = undefined;
|
|
@@ -2145,7 +2211,7 @@ const MgInputRadio = class {
|
|
|
2145
2211
|
*
|
|
2146
2212
|
* @returns {HTMLInputElement} element
|
|
2147
2213
|
*/
|
|
2148
|
-
this.getInvalidElement = () => this.inputs.find((
|
|
2214
|
+
this.getInvalidElement = () => this.inputs.find((input) => !input.disabled && !input.readOnly && !input.checkValidity());
|
|
2149
2215
|
}
|
|
2150
2216
|
handleValue(newValue) {
|
|
2151
2217
|
this.valueChange.emit(newValue);
|
|
@@ -2167,6 +2233,16 @@ const MgInputRadio = class {
|
|
|
2167
2233
|
throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
|
|
2168
2234
|
}
|
|
2169
2235
|
}
|
|
2236
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2237
|
+
this.inputs.forEach(input => {
|
|
2238
|
+
input[prop] = newValue;
|
|
2239
|
+
});
|
|
2240
|
+
this.checkValidity();
|
|
2241
|
+
if (this.hasDisplayedError) {
|
|
2242
|
+
this.setErrorMessage();
|
|
2243
|
+
this.hasDisplayedError = false;
|
|
2244
|
+
}
|
|
2245
|
+
}
|
|
2170
2246
|
/**
|
|
2171
2247
|
* Public method to display errors
|
|
2172
2248
|
*
|
|
@@ -2174,7 +2250,8 @@ const MgInputRadio = class {
|
|
|
2174
2250
|
*/
|
|
2175
2251
|
async displayError() {
|
|
2176
2252
|
this.checkValidity();
|
|
2177
|
-
this.
|
|
2253
|
+
this.setErrorMessage();
|
|
2254
|
+
this.hasDisplayedError = this.invalid;
|
|
2178
2255
|
}
|
|
2179
2256
|
/*************
|
|
2180
2257
|
* Lifecycle *
|
|
@@ -2202,17 +2279,23 @@ const MgInputRadio = class {
|
|
|
2202
2279
|
* @returns {HTMLElement} HTML Element
|
|
2203
2280
|
*/
|
|
2204
2281
|
render() {
|
|
2205
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, mgWidth: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el =>
|
|
2282
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, disabled: this.disabled, readonly: this.readonly, mgWidth: undefined, value: this.value, readonlyValue: this.value, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: true }, h("ul", { class: { 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList } }, this.options.map((input, index) => (h("li", { class: { 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled } }, h("input", { type: "radio", id: this.identifier + '_' + index, name: this.identifier, value: index, checked: JSON.stringify(this.value) === JSON.stringify(this.options[index].value), disabled: this.disabled || input.disabled, required: this.required, onBlur: this.handleBlur, onInput: this.handleInput, ref: el => {
|
|
2283
|
+
if (el !== null)
|
|
2284
|
+
this.inputs[index] = el;
|
|
2285
|
+
} }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
|
|
2206
2286
|
}
|
|
2207
2287
|
get element() { return getElement(this); }
|
|
2208
2288
|
static get watchers() { return {
|
|
2209
2289
|
"value": ["handleValue"],
|
|
2210
|
-
"items": ["validateItems"]
|
|
2290
|
+
"items": ["validateItems"],
|
|
2291
|
+
"required": ["handleValidityChange"],
|
|
2292
|
+
"readonly": ["handleValidityChange"],
|
|
2293
|
+
"disabled": ["handleValidityChange"]
|
|
2211
2294
|
}; }
|
|
2212
2295
|
};
|
|
2213
2296
|
MgInputRadio.style = mgInputRadioCss;
|
|
2214
2297
|
|
|
2215
|
-
const mgInputSelectCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input__box{width:100%;padding-top:0;padding-bottom:0;padding-right:1rem}";
|
|
2298
|
+
const mgInputSelectCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input__box{width:100%;padding-top:0;padding-bottom:0;padding-right:1rem}.mg-input.mg-input--select:not(.mg-input--label-on-top) .mg-input__box{max-width:unset}";
|
|
2216
2299
|
|
|
2217
2300
|
/**
|
|
2218
2301
|
* Check if item is a well configured option
|
|
@@ -2255,8 +2338,8 @@ const MgInputSelect = class {
|
|
|
2255
2338
|
registerInstance(this, hostRef);
|
|
2256
2339
|
this.valueChange = createEvent(this, "value-change", 7);
|
|
2257
2340
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
2258
|
-
//
|
|
2259
|
-
this.
|
|
2341
|
+
// hasDisplayedError (triggered by blur event)
|
|
2342
|
+
this.hasDisplayedError = false;
|
|
2260
2343
|
/**
|
|
2261
2344
|
* Input name
|
|
2262
2345
|
* If not set the value equals the identifier
|
|
@@ -2295,8 +2378,8 @@ const MgInputSelect = class {
|
|
|
2295
2378
|
*/
|
|
2296
2379
|
this.handleInput = () => {
|
|
2297
2380
|
this.checkValidity();
|
|
2298
|
-
if (this.
|
|
2299
|
-
this.
|
|
2381
|
+
if (this.hasDisplayedError) {
|
|
2382
|
+
this.setErrorMessage();
|
|
2300
2383
|
}
|
|
2301
2384
|
if (this.input.value !== '') {
|
|
2302
2385
|
this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
|
|
@@ -2315,19 +2398,16 @@ const MgInputSelect = class {
|
|
|
2315
2398
|
* Check if input is valid
|
|
2316
2399
|
*/
|
|
2317
2400
|
this.checkValidity = () => {
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
//Send event
|
|
2324
|
-
this.inputValid.emit(validity);
|
|
2325
|
-
}
|
|
2401
|
+
var _a;
|
|
2402
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2403
|
+
this.invalid = !this.valid;
|
|
2404
|
+
// We need to send valid event even if it is the same value
|
|
2405
|
+
this.inputValid.emit(this.valid);
|
|
2326
2406
|
};
|
|
2327
2407
|
/**
|
|
2328
|
-
*
|
|
2408
|
+
* Set input error message
|
|
2329
2409
|
*/
|
|
2330
|
-
this.
|
|
2410
|
+
this.setErrorMessage = () => {
|
|
2331
2411
|
// Set error message
|
|
2332
2412
|
this.errorMessage = undefined;
|
|
2333
2413
|
if (!this.valid && this.input.validity.valueMissing) {
|
|
@@ -2366,6 +2446,16 @@ const MgInputSelect = class {
|
|
|
2366
2446
|
throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
|
|
2367
2447
|
}
|
|
2368
2448
|
}
|
|
2449
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2450
|
+
if (this.input !== undefined) {
|
|
2451
|
+
this.input[prop] = newValue;
|
|
2452
|
+
this.checkValidity();
|
|
2453
|
+
if (this.hasDisplayedError) {
|
|
2454
|
+
this.setErrorMessage();
|
|
2455
|
+
this.hasDisplayedError = false;
|
|
2456
|
+
}
|
|
2457
|
+
}
|
|
2458
|
+
}
|
|
2369
2459
|
/**
|
|
2370
2460
|
* Public method to display errors
|
|
2371
2461
|
*
|
|
@@ -2373,8 +2463,8 @@ const MgInputSelect = class {
|
|
|
2373
2463
|
*/
|
|
2374
2464
|
async displayError() {
|
|
2375
2465
|
this.checkValidity();
|
|
2376
|
-
this.
|
|
2377
|
-
this.
|
|
2466
|
+
this.setErrorMessage();
|
|
2467
|
+
this.hasDisplayedError = this.invalid;
|
|
2378
2468
|
}
|
|
2379
2469
|
/*************
|
|
2380
2470
|
* Lifecycle *
|
|
@@ -2406,18 +2496,24 @@ const MgInputSelect = class {
|
|
|
2406
2496
|
* @returns {HTMLElement} HTML Element
|
|
2407
2497
|
*/
|
|
2408
2498
|
render() {
|
|
2409
|
-
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("select", { class: "mg-input__box", id: this.identifier, name: this.name, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el =>
|
|
2499
|
+
return (h(MgInput, { identifier: this.identifier, classList: this.classList, ariaDescribedbyIDs: [], label: this.label, labelOnTop: this.labelOnTop, labelHide: this.labelHide, required: this.required, readonly: this.readonly, mgWidth: this.mgWidth, disabled: this.disabled, value: this.value, readonlyValue: this.readonlyValue, tooltip: this.tooltip, helpText: this.helpText, errorMessage: this.errorMessage, isFieldset: false }, h("select", { class: "mg-input__box", id: this.identifier, name: this.name, title: this.placeholder, disabled: this.disabled, required: this.required, onInput: this.handleInput, onBlur: this.handleBlur, ref: el => {
|
|
2500
|
+
if (el !== null)
|
|
2501
|
+
this.input = el;
|
|
2502
|
+
} }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
|
|
2410
2503
|
h("option", { value: "", disabled: this.placeholderDisabled && this.valueExist }, this.placeholder)), this.options.map(option => option.group !== undefined ? (h("optgroup", { label: option.group }, option.options.map(optgroup => (h("option", { value: optgroup.title, selected: JSON.stringify(this.value) === JSON.stringify(optgroup.value), disabled: optgroup.disabled }, optgroup.title))))) : (h("option", { value: option.title, selected: JSON.stringify(this.value) === JSON.stringify(option.value), disabled: option.disabled }, option.title))))));
|
|
2411
2504
|
}
|
|
2412
2505
|
get element() { return getElement(this); }
|
|
2413
2506
|
static get watchers() { return {
|
|
2414
2507
|
"value": ["handleValue"],
|
|
2415
|
-
"items": ["validateItems"]
|
|
2508
|
+
"items": ["validateItems"],
|
|
2509
|
+
"required": ["handleValidityChange"],
|
|
2510
|
+
"readonly": ["handleValidityChange"],
|
|
2511
|
+
"disabled": ["handleValidityChange"]
|
|
2416
2512
|
}; }
|
|
2417
2513
|
};
|
|
2418
2514
|
MgInputSelect.style = mgInputSelectCss;
|
|
2419
2515
|
|
|
2420
|
-
const mgInputTextCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input.mg-input--has-icon .mg-input__with-character-left>mg-icon{position:absolute;top:50%;left:var(--mg-inputs-spacer);color:var(--mg-inputs-color);transform:translateY(-50%)}.mg-input.mg-input--has-icon .mg-input__with-character-left .mg-input__box{padding-left:calc(var(--mg-icon-regular-size) + var(--mg-inputs-spacer) * 2)}.mg-input__with-character-left{position:relative;display:inline-flex}.mg-input--width-full .mg-input__with-character-left{width:100%}.mg-input.is-focused .mg-input__with-character-left .mg-input__box{padding-right:calc(var(--mg-character-left-message-length) * 1ch + 0.8rem)}.mg-input__with-character-left mg-character-left{position:absolute;display:none;top:50%;right:1rem;opacity:0.6;transform:translateY(-50%);font-size:1.1rem}.mg-input.is-focused .mg-input__with-character-left mg-character-left{display:block}";
|
|
2516
|
+
const mgInputTextCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input.mg-input--has-icon .mg-input__with-character-left>mg-icon{position:absolute;top:50%;left:var(--mg-inputs-spacer);color:var(--mg-inputs-color);transform:translateY(-50%)}.mg-input.mg-input--has-icon .mg-input__with-character-left .mg-input__box{padding-left:calc(var(--mg-icon-regular-size) + var(--mg-inputs-spacer) * 2)}.mg-input__with-character-left{position:relative;display:inline-flex}.mg-input--width-full .mg-input__with-character-left{width:100%}.mg-input.is-focused .mg-input__with-character-left .mg-input__box{padding-right:calc(var(--mg-character-left-message-length) * 1ch + 0.8rem)}.mg-input__with-character-left mg-character-left{position:absolute;display:none;top:50%;right:1rem;opacity:0.6;transform:translateY(-50%);font-size:1.1rem}.mg-input.is-focused .mg-input__with-character-left mg-character-left{display:block}";
|
|
2421
2517
|
|
|
2422
2518
|
const MgInputText = class {
|
|
2423
2519
|
constructor(hostRef) {
|
|
@@ -2427,12 +2523,12 @@ const MgInputText = class {
|
|
|
2427
2523
|
/************
|
|
2428
2524
|
* Internal *
|
|
2429
2525
|
************/
|
|
2430
|
-
//
|
|
2526
|
+
// Classes
|
|
2431
2527
|
this.classFocus = 'is-focused';
|
|
2432
2528
|
this.classIsInputGroupAppend = 'mg-input--is-input-group-append';
|
|
2433
2529
|
this.classHasIcon = 'mg-input--has-icon';
|
|
2434
|
-
//
|
|
2435
|
-
this.
|
|
2530
|
+
// hasDisplayedError (triggered by blur event)
|
|
2531
|
+
this.hasDisplayedError = false;
|
|
2436
2532
|
/**
|
|
2437
2533
|
* Input name
|
|
2438
2534
|
* If not set the value equals the identifier
|
|
@@ -2481,8 +2577,8 @@ const MgInputText = class {
|
|
|
2481
2577
|
*/
|
|
2482
2578
|
this.handleInput = () => {
|
|
2483
2579
|
this.checkValidity();
|
|
2484
|
-
if (this.
|
|
2485
|
-
this.
|
|
2580
|
+
if (this.hasDisplayedError) {
|
|
2581
|
+
this.setErrorMessage();
|
|
2486
2582
|
}
|
|
2487
2583
|
this.value = this.input.value;
|
|
2488
2584
|
};
|
|
@@ -2513,21 +2609,18 @@ const MgInputText = class {
|
|
|
2513
2609
|
* @returns {void}
|
|
2514
2610
|
*/
|
|
2515
2611
|
this.checkValidity = () => {
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
//Send event
|
|
2522
|
-
this.inputValid.emit(validity);
|
|
2523
|
-
}
|
|
2612
|
+
var _a;
|
|
2613
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
|
|
2614
|
+
this.invalid = !this.valid;
|
|
2615
|
+
// We need to send valid event even if it is the same value
|
|
2616
|
+
this.inputValid.emit(this.valid);
|
|
2524
2617
|
};
|
|
2525
2618
|
/**
|
|
2526
|
-
*
|
|
2619
|
+
* Set input error message
|
|
2527
2620
|
*
|
|
2528
2621
|
* @returns {void}
|
|
2529
2622
|
*/
|
|
2530
|
-
this.
|
|
2623
|
+
this.setErrorMessage = () => {
|
|
2531
2624
|
// Set error message
|
|
2532
2625
|
this.errorMessage = undefined;
|
|
2533
2626
|
// Does not match pattern
|
|
@@ -2540,7 +2633,7 @@ const MgInputText = class {
|
|
|
2540
2633
|
}
|
|
2541
2634
|
};
|
|
2542
2635
|
/**
|
|
2543
|
-
* Validate
|
|
2636
|
+
* Validate pattern configuration
|
|
2544
2637
|
*
|
|
2545
2638
|
* @returns {void}
|
|
2546
2639
|
*/
|
|
@@ -2579,6 +2672,16 @@ const MgInputText = class {
|
|
|
2579
2672
|
this.classList.delete(this.classHasIcon);
|
|
2580
2673
|
}
|
|
2581
2674
|
}
|
|
2675
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2676
|
+
if (this.input !== undefined) {
|
|
2677
|
+
this.input[prop] = newValue;
|
|
2678
|
+
this.checkValidity();
|
|
2679
|
+
if (this.hasDisplayedError) {
|
|
2680
|
+
this.setErrorMessage();
|
|
2681
|
+
this.hasDisplayedError = false;
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2582
2685
|
/**
|
|
2583
2686
|
* Public method to play input focus
|
|
2584
2687
|
*
|
|
@@ -2594,8 +2697,8 @@ const MgInputText = class {
|
|
|
2594
2697
|
*/
|
|
2595
2698
|
async displayError() {
|
|
2596
2699
|
this.checkValidity();
|
|
2597
|
-
this.
|
|
2598
|
-
this.
|
|
2700
|
+
this.setErrorMessage();
|
|
2701
|
+
this.hasDisplayedError = this.invalid;
|
|
2599
2702
|
}
|
|
2600
2703
|
/*************
|
|
2601
2704
|
* Lifecycle *
|
|
@@ -2630,17 +2733,23 @@ const MgInputText = class {
|
|
|
2630
2733
|
'--mg-character-left-message-length': (this.displayCharacterLeft
|
|
2631
2734
|
? (this.maxlength - (this.value || '').length).toString().length + this.maxlength.toString().length + 1
|
|
2632
2735
|
: 0).toString(),
|
|
2633
|
-
} }, this.icon !== undefined && h("mg-icon", { icon: this.icon }), h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
2736
|
+
} }, this.icon !== undefined && h("mg-icon", { icon: this.icon }), h("input", { type: this.type, class: "mg-input__box", value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, maxlength: this.maxlength, disabled: this.disabled, required: this.required, pattern: this.pattern, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
2737
|
+
if (el !== null)
|
|
2738
|
+
this.input = el;
|
|
2739
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))), h("slot", { name: "append-input" })));
|
|
2634
2740
|
}
|
|
2635
2741
|
get element() { return getElement(this); }
|
|
2636
2742
|
static get watchers() { return {
|
|
2637
2743
|
"value": ["handleValue"],
|
|
2638
|
-
"icon": ["validateIcon"]
|
|
2744
|
+
"icon": ["validateIcon"],
|
|
2745
|
+
"required": ["handleValidityChange"],
|
|
2746
|
+
"readonly": ["handleValidityChange"],
|
|
2747
|
+
"disabled": ["handleValidityChange"]
|
|
2639
2748
|
}; }
|
|
2640
2749
|
};
|
|
2641
2750
|
MgInputText.style = mgInputTextCss;
|
|
2642
2751
|
|
|
2643
|
-
const mgInputTextareaCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{width:100%}.mg-input.mg-input--width-16 .mg-input__box{width:21rem}.mg-input.mg-input--width-4 .mg-input__box{width:7rem}.mg-input.mg-input--width-2 .mg-input__box{width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{display:block;height:auto;resize:none}.mg-input .mg-input__box.mg-input__box--resizable{resize:both}.mg-input .mg-input__box.mg-input__box--resizable-horizontal{resize:horizontal}.mg-input .mg-input__box.mg-input__box--resizable-vertical{resize:vertical}.mg-input__with-character-left{width:100%}.mg-input__with-character-left mg-character-left{display:block;visibility:hidden;margin-top:0.2rem;text-align:end}.mg-input.is-focused .mg-input__with-character-left mg-character-left{visibility:visible}@-moz-document url-prefix(){.mg-input__box{overflow-x:hidden}}";
|
|
2752
|
+
const mgInputTextareaCss = ":host{display:block}.mg-input{display:flex;align-items:flex-start;min-height:var(--default-size);max-width:100%;margin-bottom:var(--mg-inputs-margin-bottom, 0);}.mg-input mg-input-title{flex-shrink:var(--mg-inputs-shrink, 1);width:var(--mg-inputs-title-width, auto);margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);margin-right:var(--mg-inputs-title-horizontal-space, var(--mg-inputs-spacer));text-align:right}.mg-input.mg-input--label-on-top{flex-direction:column}.mg-input.mg-input--label-on-top .mg-input__input-container{width:100%}.mg-input__title{display:flex;align-items:baseline;margin-bottom:0.3rem}.mg-input__title mg-input-title{flex-shrink:1;width:auto;margin-top:0;margin-right:var(--mg-inputs-spacer);text-align:left}.mg-input__title mg-tooltip{margin-top:0}.mg-input__title mg-icon{display:inline-flex;vertical-align:text-bottom}.mg-input__input-container{min-height:var(--default-size);}.mg-input__input-container>strong{display:inline-block;margin-top:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2);min-height:var(--font-size)}.mg-input__input-container mg-tooltip{display:inline-flex;width:var(--mg-icon-regular-size);height:var(--mg-icon-regular-size);margin-left:var(--mg-inputs-spacer)}.mg-input__input-container .mg-input__help-text,.mg-input__input-container .mg-input__error{text-align:start;font-size:1.2rem}.mg-input__input{display:flex;}.mg-input__input mg-tooltip{margin-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input__input.mg-input__input--has-error .mg-input__box{border-color:hsl(var(--color-danger))}.mg-input__input+.mg-input__help-text,.mg-input__input+.mg-input__error{margin-top:0.5rem}.mg-input__error{display:inline-block;margin-top:0.2rem;padding:0.3rem 0.8rem;border-radius:0.3rem;background:hsl(var(--mg-inputs-error-bg-color));color:hsl(var(--color-danger))}.mg-input__input mg-icon,.mg-input__error mg-icon{display:flex}.mg-input__box{padding:calc((var(--default-size) - var(--font-size) * var(--line-height)) / 2) var(--mg-inputs-spacer);height:var(--default-size);box-sizing:border-box;border-width:var(--mg-inputs-border-width);border-style:solid;border-color:var(--mg-inputs-color);border-radius:var(--mg-inputs-border-radius);background-color:hsl(var(--color-light));font-family:inherit;color:hsl(var(--color-dark));font-size:var(--font-size);text-align:var(--mg-inputs-text-align, left)}.mg-input__box::placeholder{color:var(--mg-inputs-color);font-style:italic}.mg-input__box:focus{box-shadow:0 0 0.6rem hsla(var(--mg-inputs-color-shadow-focus-hsl), 0.5)}.mg-input__box:disabled{opacity:0.3}.mg-input.mg-input--is-input-group-append{--mg-button-border-radius-top-left:0;--mg-button-border-radius-bottom-left:0;}.mg-input.mg-input--is-input-group-append .mg-input__box{margin-right:-0.1rem;border-top-right-radius:0%;border-bottom-right-radius:0%}.mg-input.mg-input--is-input-group-append .mg-input__box:focus-visible{outline-style:solid;outline-offset:-0.2rem;outline-width:0.2rem}.mg-input.mg-input--is-input-group-append.mg-input--readonly slot[name=append-input]{display:none}.mg-input.mg-input--label-on-top .mg-input__box{width:auto;max-width:100%}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]){--mg-button-border-radius-top-right:0;--mg-button-border-radius-bottom-right:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:not(:last-of-type)){--mg-button-border-right-width:0}.mg-input.mg-input--has-buttons-group-append ::slotted([slot=append-input]:last-of-type){--mg-button-border-radius-top-right:var(--mg-inputs-border-radius);--mg-button-border-radius-bottom-right:var(--mg-inputs-border-radius)}.mg-input.mg-input--is-append-input-slot-content:not(.mg-input--readonly) ::slotted([slot=append-input]){padding-top:calc((var(--default-size) - var(--mg-icon-regular-size)) / 2)}.mg-input.mg-input--width-full:not(.mg-input--label-on-top){justify-content:space-between}.mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box{width:100%}.mg-input.mg-input--width-full .mg-input__input-container{flex:auto;width:100%}.mg-input.mg-input--width-full .mg-input__input-container .mg-input__box{max-width:100%}.mg-input:not(.mg-input--label-on-top) .mg-input__box{width:100%;max-width:calc(17.7rem + var(--mg-inputs-spacer) * 2);min-width:5rem}.mg-input.mg-input--width-16 .mg-input__input-container{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input{width:100%;max-width:21rem}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left{width:100%}.mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box{max-width:21rem;min-width:100%}.mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box{max-width:7rem}.mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box{max-width:5rem}.mg-input mg-character-left{opacity:0.6;font-size:1.1rem}.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__help-text,.mg-input.mg-input--has-display-character-left .mg-input__input+.mg-input__error{margin-top:0}.sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}.mg-input .mg-input__box{display:block;height:auto;resize:none}.mg-input .mg-input__box.mg-input__box--resizable{resize:both}.mg-input .mg-input__box.mg-input__box--resizable-horizontal{resize:horizontal}.mg-input .mg-input__box.mg-input__box--resizable-vertical{resize:vertical}.mg-input__with-character-left{width:100%}.mg-input__with-character-left mg-character-left{display:block;visibility:hidden;margin-top:0.2rem;text-align:end}.mg-input.is-focused .mg-input__with-character-left mg-character-left{visibility:visible}@-moz-document url-prefix(){.mg-input__box{overflow-x:hidden}}";
|
|
2644
2753
|
|
|
2645
2754
|
const MgInputTextarea = class {
|
|
2646
2755
|
constructor(hostRef) {
|
|
@@ -2650,11 +2759,11 @@ const MgInputTextarea = class {
|
|
|
2650
2759
|
/************
|
|
2651
2760
|
* Internal *
|
|
2652
2761
|
************/
|
|
2653
|
-
//
|
|
2762
|
+
// Classes
|
|
2654
2763
|
this.classFocus = 'is-focused';
|
|
2655
2764
|
this.classHasDisplayCharacterLeft = 'mg-input--has-display-character-left';
|
|
2656
|
-
//
|
|
2657
|
-
this.
|
|
2765
|
+
// hasDisplayedError (triggered by blur event)
|
|
2766
|
+
this.hasDisplayedError = false;
|
|
2658
2767
|
/**
|
|
2659
2768
|
* Input name
|
|
2660
2769
|
* If not set the value equals the identifier
|
|
@@ -2704,9 +2813,9 @@ const MgInputTextarea = class {
|
|
|
2704
2813
|
* Handle input event
|
|
2705
2814
|
*/
|
|
2706
2815
|
this.handleInput = () => {
|
|
2707
|
-
if (this.
|
|
2816
|
+
if (this.hasDisplayedError) {
|
|
2708
2817
|
this.checkValidity();
|
|
2709
|
-
this.
|
|
2818
|
+
this.setErrorMessage();
|
|
2710
2819
|
}
|
|
2711
2820
|
this.value = this.input.value;
|
|
2712
2821
|
};
|
|
@@ -2738,19 +2847,16 @@ const MgInputTextarea = class {
|
|
|
2738
2847
|
* Check if input is valid
|
|
2739
2848
|
*/
|
|
2740
2849
|
this.checkValidity = () => {
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
//Send event
|
|
2747
|
-
this.inputValid.emit(validity);
|
|
2748
|
-
}
|
|
2850
|
+
var _a;
|
|
2851
|
+
this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity());
|
|
2852
|
+
this.invalid = !this.valid;
|
|
2853
|
+
// We need to send valid event even if it is the same value
|
|
2854
|
+
this.inputValid.emit(this.valid);
|
|
2749
2855
|
};
|
|
2750
2856
|
/**
|
|
2751
|
-
*
|
|
2857
|
+
* Set input error message
|
|
2752
2858
|
*/
|
|
2753
|
-
this.
|
|
2859
|
+
this.setErrorMessage = () => {
|
|
2754
2860
|
// Set error message
|
|
2755
2861
|
this.errorMessage = undefined;
|
|
2756
2862
|
// Does not match pattern
|
|
@@ -2778,6 +2884,16 @@ const MgInputTextarea = class {
|
|
|
2778
2884
|
this.checkValidity();
|
|
2779
2885
|
this.valueChange.emit(newValue);
|
|
2780
2886
|
}
|
|
2887
|
+
handleValidityChange(newValue, _oldValue, prop) {
|
|
2888
|
+
if (this.input !== undefined) {
|
|
2889
|
+
this.input[prop] = newValue;
|
|
2890
|
+
this.checkValidity();
|
|
2891
|
+
if (this.hasDisplayedError) {
|
|
2892
|
+
this.setErrorMessage();
|
|
2893
|
+
this.hasDisplayedError = false;
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2781
2897
|
validateDisplayCharacterLeft(newValue) {
|
|
2782
2898
|
if (newValue) {
|
|
2783
2899
|
this.classList.add(this.classHasDisplayCharacterLeft);
|
|
@@ -2793,8 +2909,8 @@ const MgInputTextarea = class {
|
|
|
2793
2909
|
*/
|
|
2794
2910
|
async displayError() {
|
|
2795
2911
|
this.checkValidity();
|
|
2796
|
-
this.
|
|
2797
|
-
this.
|
|
2912
|
+
this.setErrorMessage();
|
|
2913
|
+
this.hasDisplayedError = this.invalid;
|
|
2798
2914
|
}
|
|
2799
2915
|
/*************
|
|
2800
2916
|
* Lifecycle *
|
|
@@ -2829,11 +2945,17 @@ const MgInputTextarea = class {
|
|
|
2829
2945
|
'mg-input__box--resizable': this.resizable === 'both',
|
|
2830
2946
|
'mg-input__box--resizable-horizontal': this.resizable === 'horizontal',
|
|
2831
2947
|
'mg-input__box--resizable-vertical': this.resizable === 'vertical',
|
|
2832
|
-
}, value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, rows: this.rows, maxlength: this.maxlength, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el =>
|
|
2948
|
+
}, value: this.value, id: this.identifier, name: this.name, placeholder: this.placeholder, title: this.placeholder, rows: this.rows, maxlength: this.maxlength, disabled: this.disabled, required: this.required, onInput: this.handleInput, onFocus: this.handleFocus, onBlur: this.handleBlur, ref: el => {
|
|
2949
|
+
if (el !== null)
|
|
2950
|
+
this.input = el;
|
|
2951
|
+
} }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength })))));
|
|
2833
2952
|
}
|
|
2834
2953
|
get element() { return getElement(this); }
|
|
2835
2954
|
static get watchers() { return {
|
|
2836
2955
|
"value": ["handleValue"],
|
|
2956
|
+
"required": ["handleValidityChange"],
|
|
2957
|
+
"readonly": ["handleValidityChange"],
|
|
2958
|
+
"disabled": ["handleValidityChange"],
|
|
2837
2959
|
"displayCharacterLeft": ["validateDisplayCharacterLeft"]
|
|
2838
2960
|
}; }
|
|
2839
2961
|
};
|
|
@@ -2906,7 +3028,7 @@ const MgInputToggle = class {
|
|
|
2906
3028
|
/************
|
|
2907
3029
|
* Internal *
|
|
2908
3030
|
************/
|
|
2909
|
-
//
|
|
3031
|
+
// Classes
|
|
2910
3032
|
this.classReadonly = 'mg-input--toggle-readonly';
|
|
2911
3033
|
this.classDisabled = 'mg-input--toggle-disabled';
|
|
2912
3034
|
this.classIsActive = 'mg-input--toggle-is-active';
|
|
@@ -3104,7 +3226,7 @@ const MgMessage = class {
|
|
|
3104
3226
|
/************
|
|
3105
3227
|
* Internal *
|
|
3106
3228
|
************/
|
|
3107
|
-
//
|
|
3229
|
+
// Classes
|
|
3108
3230
|
this.classHide = 'mg-message--hide';
|
|
3109
3231
|
// IDs
|
|
3110
3232
|
this.closeButtonId = '';
|
|
@@ -3382,10 +3504,6 @@ const MgModal = class {
|
|
|
3382
3504
|
*/
|
|
3383
3505
|
componentDidLoad() {
|
|
3384
3506
|
new MutationObserver(mutationList => {
|
|
3385
|
-
/*
|
|
3386
|
-
TODO find a way to cover this callback
|
|
3387
|
-
*/
|
|
3388
|
-
/* istanbul ignore next */
|
|
3389
3507
|
if (mutationList.some(mutation => mutation.attributeName === 'aria-hidden' && mutation.target.ariaHidden === null)) {
|
|
3390
3508
|
this.setFocus();
|
|
3391
3509
|
}
|
|
@@ -5903,7 +6021,7 @@ const MgTag = class {
|
|
|
5903
6021
|
/************
|
|
5904
6022
|
* Internal *
|
|
5905
6023
|
************/
|
|
5906
|
-
//
|
|
6024
|
+
// Classes
|
|
5907
6025
|
this.classOutline = `mg-tag--outline`;
|
|
5908
6026
|
/**************
|
|
5909
6027
|
* Decorators *
|