@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.
Files changed (67) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mg-badge_27.cjs.entry.js +354 -236
  3. package/dist/cjs/mg-components.cjs.js +1 -1
  4. package/dist/collection/components/atoms/mg-badge/mg-badge.js +1 -1
  5. package/dist/collection/components/atoms/mg-button/mg-button.js +3 -3
  6. package/dist/collection/components/atoms/mg-tag/mg-tag.js +1 -1
  7. package/dist/collection/components/molecules/inputs/MgInput.js +3 -11
  8. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +41 -20
  9. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +50 -39
  10. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.css +25 -6
  11. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +42 -33
  12. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.css +25 -6
  13. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +36 -17
  14. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +35 -14
  15. package/dist/collection/components/molecules/inputs/mg-input-select/doc/mg-input-select.stories.js +2 -3
  16. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.css +28 -6
  17. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +36 -17
  18. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.css +25 -6
  19. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +38 -19
  20. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.css +25 -6
  21. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +37 -18
  22. package/dist/collection/components/molecules/inputs/mg-input-toggle/mg-input-toggle.js +1 -1
  23. package/dist/collection/components/molecules/mg-form/mg-form.js +73 -27
  24. package/dist/collection/components/molecules/mg-illustrated-message/doc/mg-illustrated-message.stories.js +6 -6
  25. package/dist/collection/components/molecules/mg-message/mg-message.js +1 -1
  26. package/dist/collection/components/molecules/mg-modal/mg-modal.js +0 -4
  27. package/dist/collection/utils/unit.test.utils.js +51 -0
  28. package/dist/collection/variables.css +6 -6
  29. package/dist/components/MgInput.js +4 -12
  30. package/dist/components/mg-badge2.js +1 -1
  31. package/dist/components/mg-button2.js +3 -3
  32. package/dist/components/mg-form.js +67 -26
  33. package/dist/components/mg-input-checkbox.js +36 -21
  34. package/dist/components/mg-input-date.js +44 -39
  35. package/dist/components/mg-input-numeric.js +37 -34
  36. package/dist/components/mg-input-password.js +32 -19
  37. package/dist/components/mg-input-radio.js +30 -15
  38. package/dist/components/mg-input-select2.js +32 -19
  39. package/dist/components/mg-input-text2.js +34 -21
  40. package/dist/components/mg-input-textarea.js +32 -19
  41. package/dist/components/mg-input-toggle.js +1 -1
  42. package/dist/components/mg-message.js +1 -1
  43. package/dist/components/mg-modal.js +0 -4
  44. package/dist/components/mg-tag.js +1 -1
  45. package/dist/esm/loader.js +1 -1
  46. package/dist/esm/mg-badge_27.entry.js +354 -236
  47. package/dist/esm/mg-components.js +1 -1
  48. package/dist/mg-components/mg-components.css +1 -1
  49. package/dist/mg-components/mg-components.esm.js +1 -1
  50. package/dist/mg-components/p-b2b07c3f.entry.js +1 -0
  51. package/dist/mg-components/variables.css +6 -6
  52. package/dist/types/components/atoms/mg-button/mg-button.d.ts +2 -2
  53. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +10 -8
  54. package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +3 -8
  55. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +3 -8
  56. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +4 -3
  57. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +4 -2
  58. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +4 -3
  59. package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +5 -4
  60. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +4 -3
  61. package/dist/types/components/molecules/mg-form/mg-form.d.ts +21 -1
  62. package/dist/types/components/molecules/mg-message/mg-message.d.ts +3 -0
  63. package/dist/types/components/molecules/mg-modal/mg-modal.d.ts +3 -0
  64. package/package.json +7 -8
  65. package/dist/collection/utils/test.utils.js +0 -38
  66. package/dist/mg-components/p-e131701a.entry.js +0 -1
  67. package/dist/types/utils/test.utils.d.ts +0 -17
@@ -4,8 +4,8 @@ import { ClassList } from '../../../../utils/components.utils';
4
4
  import { initLocales } from '../../../../locales';
5
5
  export class MgInputPassword {
6
6
  constructor() {
7
- // hasError (triggered by blur event)
8
- this.hasError = false;
7
+ // hasDisplayedError (triggered by blur event)
8
+ this.hasDisplayedError = false;
9
9
  /**
10
10
  * Input name
11
11
  * If not set the value equals the identifier
@@ -40,8 +40,8 @@ export class MgInputPassword {
40
40
  */
41
41
  this.handleInput = () => {
42
42
  this.checkValidity();
43
- if (this.hasError) {
44
- this.checkError();
43
+ if (this.hasDisplayedError) {
44
+ this.setErrorMessage();
45
45
  }
46
46
  this.value = this.input.value;
47
47
  };
@@ -55,19 +55,16 @@ export class MgInputPassword {
55
55
  * Check if input is valid
56
56
  */
57
57
  this.checkValidity = () => {
58
- if (!this.readonly && this.input !== undefined) {
59
- const validity = this.input.checkValidity();
60
- // Set validity
61
- this.valid = validity;
62
- this.invalid = !validity;
63
- //Send event
64
- this.inputValid.emit(validity);
65
- }
58
+ var _a;
59
+ this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
60
+ this.invalid = !this.valid;
61
+ // We need to send valid event even if it is the same value
62
+ this.inputValid.emit(this.valid);
66
63
  };
67
64
  /**
68
- * Check input errors
65
+ * Set input error message
69
66
  */
70
- this.checkError = () => {
67
+ this.setErrorMessage = () => {
71
68
  // Set error message
72
69
  this.errorMessage = undefined;
73
70
  // required
@@ -79,6 +76,16 @@ export class MgInputPassword {
79
76
  handleValue(newValue) {
80
77
  this.valueChange.emit(newValue);
81
78
  }
79
+ handleValidityChange(newValue, _oldValue, prop) {
80
+ if (this.input !== undefined) {
81
+ this.input[prop] = newValue;
82
+ this.checkValidity();
83
+ if (this.hasDisplayedError) {
84
+ this.setErrorMessage();
85
+ this.hasDisplayedError = false;
86
+ }
87
+ }
88
+ }
82
89
  /**
83
90
  * Public method to display errors
84
91
  *
@@ -86,8 +93,8 @@ export class MgInputPassword {
86
93
  */
87
94
  async displayError() {
88
95
  this.checkValidity();
89
- this.checkError();
90
- this.hasError = this.invalid;
96
+ this.setErrorMessage();
97
+ this.hasDisplayedError = this.invalid;
91
98
  }
92
99
  /*************
93
100
  * Lifecycle *
@@ -113,7 +120,10 @@ export class MgInputPassword {
113
120
  * @returns {HTMLElement} HTML Element
114
121
  */
115
122
  render() {
116
- 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 => (this.input = el) })));
123
+ 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 => {
124
+ if (el !== null)
125
+ this.input = el;
126
+ } })));
117
127
  }
118
128
  static get is() { return "mg-input-password"; }
119
129
  static get encapsulation() { return "shadow"; }
@@ -464,6 +474,15 @@ export class MgInputPassword {
464
474
  return [{
465
475
  "propName": "value",
466
476
  "methodName": "handleValue"
477
+ }, {
478
+ "propName": "required",
479
+ "methodName": "handleValidityChange"
480
+ }, {
481
+ "propName": "readonly",
482
+ "methodName": "handleValidityChange"
483
+ }, {
484
+ "propName": "disabled",
485
+ "methodName": "handleValidityChange"
467
486
  }];
468
487
  }
469
488
  }
@@ -18,6 +18,8 @@ export class MgInputRadio {
18
18
  ************/
19
19
  // HTML selector
20
20
  this.inputs = [];
21
+ // hasDisplayedError (triggered by blur event)
22
+ this.hasDisplayedError = false;
21
23
  /**
22
24
  * Input name
23
25
  * If not set the value equals the identifier
@@ -68,7 +70,7 @@ export class MgInputRadio {
68
70
  */
69
71
  this.handleBlur = () => {
70
72
  this.checkValidity();
71
- this.checkError();
73
+ this.setErrorMessage();
72
74
  };
73
75
  /**
74
76
  * Check if input is valid
@@ -76,21 +78,17 @@ export class MgInputRadio {
76
78
  * @returns {void}
77
79
  */
78
80
  this.checkValidity = () => {
79
- if (!this.readonly) {
80
- const validity = this.getInvalidElement() === undefined;
81
- // Set validity
82
- this.valid = validity;
83
- this.invalid = !validity;
84
- //Send event
85
- this.inputValid.emit(validity);
86
- }
81
+ this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
82
+ this.invalid = !this.valid;
83
+ // We need to send valid event even if it is the same value
84
+ this.inputValid.emit(this.valid);
87
85
  };
88
86
  /**
89
- * Check input errors
87
+ * Set input error message
90
88
  *
91
89
  * @returns {void}
92
90
  */
93
- this.checkError = () => {
91
+ this.setErrorMessage = () => {
94
92
  const invalidElement = this.getInvalidElement();
95
93
  // Set error message
96
94
  this.errorMessage = undefined;
@@ -103,7 +101,7 @@ export class MgInputRadio {
103
101
  *
104
102
  * @returns {HTMLInputElement} element
105
103
  */
106
- this.getInvalidElement = () => this.inputs.find((element) => !element.disabled && !element.checkValidity());
104
+ this.getInvalidElement = () => this.inputs.find((input) => !input.disabled && !input.readOnly && !input.checkValidity());
107
105
  }
108
106
  handleValue(newValue) {
109
107
  this.valueChange.emit(newValue);
@@ -125,6 +123,16 @@ export class MgInputRadio {
125
123
  throw new Error('<mg-input-radio> prop "items" is required and all items must be the same type, string or RadioOption.');
126
124
  }
127
125
  }
126
+ handleValidityChange(newValue, _oldValue, prop) {
127
+ this.inputs.forEach(input => {
128
+ input[prop] = newValue;
129
+ });
130
+ this.checkValidity();
131
+ if (this.hasDisplayedError) {
132
+ this.setErrorMessage();
133
+ this.hasDisplayedError = false;
134
+ }
135
+ }
128
136
  /**
129
137
  * Public method to display errors
130
138
  *
@@ -132,7 +140,8 @@ export class MgInputRadio {
132
140
  */
133
141
  async displayError() {
134
142
  this.checkValidity();
135
- this.checkError();
143
+ this.setErrorMessage();
144
+ this.hasDisplayedError = this.invalid;
136
145
  }
137
146
  /*************
138
147
  * Lifecycle *
@@ -160,7 +169,10 @@ export class MgInputRadio {
160
169
  * @returns {HTMLElement} HTML Element
161
170
  */
162
171
  render() {
163
- 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 => this.inputs.push(el) }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
172
+ 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 => {
173
+ if (el !== null)
174
+ this.inputs[index] = el;
175
+ } }), h("label", { htmlFor: this.identifier + '_' + index }, input.title)))))));
164
176
  }
165
177
  static get is() { return "mg-input-radio"; }
166
178
  static get encapsulation() { return "shadow"; }
@@ -514,6 +526,15 @@ export class MgInputRadio {
514
526
  }, {
515
527
  "propName": "items",
516
528
  "methodName": "validateItems"
529
+ }, {
530
+ "propName": "required",
531
+ "methodName": "handleValidityChange"
532
+ }, {
533
+ "propName": "readonly",
534
+ "methodName": "handleValidityChange"
535
+ }, {
536
+ "propName": "disabled",
537
+ "methodName": "handleValidityChange"
517
538
  }];
518
539
  }
519
540
  }
@@ -18,8 +18,7 @@ export default {
18
18
  parameters: { actions: { handles: ['value-change', 'input-valid'] } },
19
19
  };
20
20
  /**
21
- * 1. camelCase arguments must be written in the template, for exemple labelOnTop must be placed in the template as label-on-top={args.labelOnTop}
22
- * 2. boolean arguments with a default true value must be added like display-character-left={args.displayCharacterLeft ? 'true' : 'false'}
21
+ * Template
23
22
  *
24
23
  * @param {any} args component arguments
25
24
  * @returns {HTMLElement} HTMLElement
@@ -40,7 +39,7 @@ MgInputSelect.args = {
40
39
  required: true,
41
40
  readonly: false,
42
41
  disabled: false,
43
- items: ['blu', 'bli', 'blo', 'bla'],
42
+ items: ['blu', 'bli', 'blo', 'le long libellé qui va faire sortir le champ mg-input-select de sa zone de confort'],
44
43
  mgWidth: undefined,
45
44
  // Tooltip
46
45
  tooltip: 'This is a tooltip',
@@ -185,21 +185,40 @@
185
185
  .mg-input.mg-input--width-full:not(.mg-input--label-on-top) {
186
186
  justify-content: space-between;
187
187
  }
188
+ .mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box {
189
+ width: 100%;
190
+ }
188
191
  .mg-input.mg-input--width-full .mg-input__input-container {
189
192
  flex: auto;
190
193
  width: 100%;
191
194
  }
192
195
  .mg-input.mg-input--width-full .mg-input__input-container .mg-input__box {
196
+ max-width: 100%;
197
+ }
198
+ .mg-input:not(.mg-input--label-on-top) .mg-input__box {
193
199
  width: 100%;
200
+ max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
201
+ min-width: 5rem;
194
202
  }
195
- .mg-input.mg-input--width-16 .mg-input__box {
196
- width: 21rem;
203
+ .mg-input.mg-input--width-16 .mg-input__input-container {
204
+ width: 100%;
197
205
  }
198
- .mg-input.mg-input--width-4 .mg-input__box {
199
- width: 7rem;
206
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
207
+ width: 100%;
208
+ max-width: 21rem;
200
209
  }
201
- .mg-input.mg-input--width-2 .mg-input__box {
202
- width: 5rem;
210
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
211
+ width: 100%;
212
+ }
213
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
214
+ max-width: 21rem;
215
+ min-width: 100%;
216
+ }
217
+ .mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
218
+ max-width: 7rem;
219
+ }
220
+ .mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
221
+ max-width: 5rem;
203
222
  }
204
223
 
205
224
  /**
@@ -228,4 +247,7 @@
228
247
  padding-top: 0;
229
248
  padding-bottom: 0;
230
249
  padding-right: 1rem;
250
+ }
251
+ .mg-input.mg-input--select:not(.mg-input--label-on-top) .mg-input__box {
252
+ max-width: unset;
231
253
  }
@@ -42,8 +42,8 @@ const groupOptions = (acc, { group, title, value, disabled }) => {
42
42
  };
43
43
  export class MgInputSelect {
44
44
  constructor() {
45
- // hasError (triggered by blur event)
46
- this.hasError = false;
45
+ // hasDisplayedError (triggered by blur event)
46
+ this.hasDisplayedError = false;
47
47
  /**
48
48
  * Input name
49
49
  * If not set the value equals the identifier
@@ -82,8 +82,8 @@ export class MgInputSelect {
82
82
  */
83
83
  this.handleInput = () => {
84
84
  this.checkValidity();
85
- if (this.hasError) {
86
- this.checkError();
85
+ if (this.hasDisplayedError) {
86
+ this.setErrorMessage();
87
87
  }
88
88
  if (this.input.value !== '') {
89
89
  this.value = allItemsAreString(this.items) ? this.input.value : this.items.find(item => item.title === this.input.value).value;
@@ -102,19 +102,16 @@ export class MgInputSelect {
102
102
  * Check if input is valid
103
103
  */
104
104
  this.checkValidity = () => {
105
- if (!this.readonly && this.input !== undefined) {
106
- const validity = this.input.checkValidity && this.input.checkValidity();
107
- // Set validity
108
- this.valid = validity;
109
- this.invalid = !validity;
110
- //Send event
111
- this.inputValid.emit(validity);
112
- }
105
+ var _a;
106
+ this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
107
+ this.invalid = !this.valid;
108
+ // We need to send valid event even if it is the same value
109
+ this.inputValid.emit(this.valid);
113
110
  };
114
111
  /**
115
- * Check input errors
112
+ * Set input error message
116
113
  */
117
- this.checkError = () => {
114
+ this.setErrorMessage = () => {
118
115
  // Set error message
119
116
  this.errorMessage = undefined;
120
117
  if (!this.valid && this.input.validity.valueMissing) {
@@ -153,6 +150,16 @@ export class MgInputSelect {
153
150
  throw new Error('<mg-input-select> prop "items" is required and all items must be the same type, string or Option.');
154
151
  }
155
152
  }
153
+ handleValidityChange(newValue, _oldValue, prop) {
154
+ if (this.input !== undefined) {
155
+ this.input[prop] = newValue;
156
+ this.checkValidity();
157
+ if (this.hasDisplayedError) {
158
+ this.setErrorMessage();
159
+ this.hasDisplayedError = false;
160
+ }
161
+ }
162
+ }
156
163
  /**
157
164
  * Public method to display errors
158
165
  *
@@ -160,8 +167,8 @@ export class MgInputSelect {
160
167
  */
161
168
  async displayError() {
162
169
  this.checkValidity();
163
- this.checkError();
164
- this.hasError = this.invalid;
170
+ this.setErrorMessage();
171
+ this.hasDisplayedError = this.invalid;
165
172
  }
166
173
  /*************
167
174
  * Lifecycle *
@@ -193,7 +200,10 @@ export class MgInputSelect {
193
200
  * @returns {HTMLElement} HTML Element
194
201
  */
195
202
  render() {
196
- 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 => (this.input = el) }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
203
+ 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 => {
204
+ if (el !== null)
205
+ this.input = el;
206
+ } }, (!this.placeholderHide || !this.valueExist) && ( // In case passed value does not match any option we display the placeholder
197
207
  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))))));
198
208
  }
199
209
  static get is() { return "mg-input-select"; }
@@ -606,6 +616,15 @@ export class MgInputSelect {
606
616
  }, {
607
617
  "propName": "items",
608
618
  "methodName": "validateItems"
619
+ }, {
620
+ "propName": "required",
621
+ "methodName": "handleValidityChange"
622
+ }, {
623
+ "propName": "readonly",
624
+ "methodName": "handleValidityChange"
625
+ }, {
626
+ "propName": "disabled",
627
+ "methodName": "handleValidityChange"
609
628
  }];
610
629
  }
611
630
  }
@@ -185,21 +185,40 @@
185
185
  .mg-input.mg-input--width-full:not(.mg-input--label-on-top) {
186
186
  justify-content: space-between;
187
187
  }
188
+ .mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box {
189
+ width: 100%;
190
+ }
188
191
  .mg-input.mg-input--width-full .mg-input__input-container {
189
192
  flex: auto;
190
193
  width: 100%;
191
194
  }
192
195
  .mg-input.mg-input--width-full .mg-input__input-container .mg-input__box {
196
+ max-width: 100%;
197
+ }
198
+ .mg-input:not(.mg-input--label-on-top) .mg-input__box {
199
+ width: 100%;
200
+ max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
201
+ min-width: 5rem;
202
+ }
203
+ .mg-input.mg-input--width-16 .mg-input__input-container {
204
+ width: 100%;
205
+ }
206
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
207
+ width: 100%;
208
+ max-width: 21rem;
209
+ }
210
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
193
211
  width: 100%;
194
212
  }
195
- .mg-input.mg-input--width-16 .mg-input__box {
196
- width: 21rem;
213
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
214
+ max-width: 21rem;
215
+ min-width: 100%;
197
216
  }
198
- .mg-input.mg-input--width-4 .mg-input__box {
199
- width: 7rem;
217
+ .mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
218
+ max-width: 7rem;
200
219
  }
201
- .mg-input.mg-input--width-2 .mg-input__box {
202
- width: 5rem;
220
+ .mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
221
+ max-width: 5rem;
203
222
  }
204
223
 
205
224
  /**
@@ -7,12 +7,12 @@ export class MgInputText {
7
7
  /************
8
8
  * Internal *
9
9
  ************/
10
- // classes
10
+ // Classes
11
11
  this.classFocus = 'is-focused';
12
12
  this.classIsInputGroupAppend = 'mg-input--is-input-group-append';
13
13
  this.classHasIcon = 'mg-input--has-icon';
14
- // hasError (triggered by blur event)
15
- this.hasError = false;
14
+ // hasDisplayedError (triggered by blur event)
15
+ this.hasDisplayedError = false;
16
16
  /**
17
17
  * Input name
18
18
  * If not set the value equals the identifier
@@ -61,8 +61,8 @@ export class MgInputText {
61
61
  */
62
62
  this.handleInput = () => {
63
63
  this.checkValidity();
64
- if (this.hasError) {
65
- this.checkError();
64
+ if (this.hasDisplayedError) {
65
+ this.setErrorMessage();
66
66
  }
67
67
  this.value = this.input.value;
68
68
  };
@@ -93,21 +93,18 @@ export class MgInputText {
93
93
  * @returns {void}
94
94
  */
95
95
  this.checkValidity = () => {
96
- if (!this.readonly && this.input !== undefined) {
97
- const validity = this.input.checkValidity();
98
- // Set validity
99
- this.valid = validity;
100
- this.invalid = !validity;
101
- //Send event
102
- this.inputValid.emit(validity);
103
- }
96
+ var _a;
97
+ this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
98
+ this.invalid = !this.valid;
99
+ // We need to send valid event even if it is the same value
100
+ this.inputValid.emit(this.valid);
104
101
  };
105
102
  /**
106
- * Check input errors
103
+ * Set input error message
107
104
  *
108
105
  * @returns {void}
109
106
  */
110
- this.checkError = () => {
107
+ this.setErrorMessage = () => {
111
108
  // Set error message
112
109
  this.errorMessage = undefined;
113
110
  // Does not match pattern
@@ -120,7 +117,7 @@ export class MgInputText {
120
117
  }
121
118
  };
122
119
  /**
123
- * Validate patern configuration
120
+ * Validate pattern configuration
124
121
  *
125
122
  * @returns {void}
126
123
  */
@@ -159,6 +156,16 @@ export class MgInputText {
159
156
  this.classList.delete(this.classHasIcon);
160
157
  }
161
158
  }
159
+ handleValidityChange(newValue, _oldValue, prop) {
160
+ if (this.input !== undefined) {
161
+ this.input[prop] = newValue;
162
+ this.checkValidity();
163
+ if (this.hasDisplayedError) {
164
+ this.setErrorMessage();
165
+ this.hasDisplayedError = false;
166
+ }
167
+ }
168
+ }
162
169
  /**
163
170
  * Public method to play input focus
164
171
  *
@@ -174,8 +181,8 @@ export class MgInputText {
174
181
  */
175
182
  async displayError() {
176
183
  this.checkValidity();
177
- this.checkError();
178
- this.hasError = this.invalid;
184
+ this.setErrorMessage();
185
+ this.hasDisplayedError = this.invalid;
179
186
  }
180
187
  /*************
181
188
  * Lifecycle *
@@ -210,7 +217,10 @@ export class MgInputText {
210
217
  '--mg-character-left-message-length': (this.displayCharacterLeft
211
218
  ? (this.maxlength - (this.value || '').length).toString().length + this.maxlength.toString().length + 1
212
219
  : 0).toString(),
213
- } }, 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 => (this.input = el) }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))), h("slot", { name: "append-input" })));
220
+ } }, 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 => {
221
+ if (el !== null)
222
+ this.input = el;
223
+ } }), this.displayCharacterLeft && this.maxlength > 0 && (h("mg-character-left", { identifier: this.characterLeftId, characters: this.value, maxlength: this.maxlength }))), h("slot", { name: "append-input" })));
214
224
  }
215
225
  static get is() { return "mg-input-text"; }
216
226
  static get encapsulation() { return "shadow"; }
@@ -688,6 +698,15 @@ export class MgInputText {
688
698
  }, {
689
699
  "propName": "icon",
690
700
  "methodName": "validateIcon"
701
+ }, {
702
+ "propName": "required",
703
+ "methodName": "handleValidityChange"
704
+ }, {
705
+ "propName": "readonly",
706
+ "methodName": "handleValidityChange"
707
+ }, {
708
+ "propName": "disabled",
709
+ "methodName": "handleValidityChange"
691
710
  }];
692
711
  }
693
712
  }
@@ -185,21 +185,40 @@
185
185
  .mg-input.mg-input--width-full:not(.mg-input--label-on-top) {
186
186
  justify-content: space-between;
187
187
  }
188
+ .mg-input.mg-input--width-full.mg-input--label-on-top .mg-input__box {
189
+ width: 100%;
190
+ }
188
191
  .mg-input.mg-input--width-full .mg-input__input-container {
189
192
  flex: auto;
190
193
  width: 100%;
191
194
  }
192
195
  .mg-input.mg-input--width-full .mg-input__input-container .mg-input__box {
196
+ max-width: 100%;
197
+ }
198
+ .mg-input:not(.mg-input--label-on-top) .mg-input__box {
199
+ width: 100%;
200
+ max-width: calc(17.7rem + var(--mg-inputs-spacer) * 2);
201
+ min-width: 5rem;
202
+ }
203
+ .mg-input.mg-input--width-16 .mg-input__input-container {
204
+ width: 100%;
205
+ }
206
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__input {
207
+ width: 100%;
208
+ max-width: 21rem;
209
+ }
210
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__with-character-left {
193
211
  width: 100%;
194
212
  }
195
- .mg-input.mg-input--width-16 .mg-input__box {
196
- width: 21rem;
213
+ .mg-input.mg-input--width-16 .mg-input__input-container .mg-input__box {
214
+ max-width: 21rem;
215
+ min-width: 100%;
197
216
  }
198
- .mg-input.mg-input--width-4 .mg-input__box {
199
- width: 7rem;
217
+ .mg-input.mg-input--width-4 .mg-input__input-container .mg-input__box {
218
+ max-width: 7rem;
200
219
  }
201
- .mg-input.mg-input--width-2 .mg-input__box {
202
- width: 5rem;
220
+ .mg-input.mg-input--width-2 .mg-input__input-container .mg-input__box {
221
+ max-width: 5rem;
203
222
  }
204
223
 
205
224
  /**