@mgdis/mg-components 5.17.0 → 5.18.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 (111) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/mg-action-more_34.cjs.entry.js +464 -157
  3. package/dist/cjs/mg-action-more_34.cjs.entry.js.map +1 -1
  4. package/dist/cjs/mg-components.cjs.js +1 -1
  5. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +31 -11
  6. package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
  7. package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.e2e.js +6 -0
  8. package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.e2e.js.map +1 -1
  9. package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.spec.js +8 -0
  10. package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.spec.js.map +1 -1
  11. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +92 -16
  12. package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
  13. package/dist/collection/components/molecules/inputs/mg-input-checkbox/test/mg-input-checkbox.spec.js +58 -1
  14. package/dist/collection/components/molecules/inputs/mg-input-checkbox/test/mg-input-checkbox.spec.js.map +1 -1
  15. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +79 -8
  16. package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
  17. package/dist/collection/components/molecules/inputs/mg-input-date/test/mg-input-date.spec.js +55 -0
  18. package/dist/collection/components/molecules/inputs/mg-input-date/test/mg-input-date.spec.js.map +1 -1
  19. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +109 -38
  20. package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
  21. package/dist/collection/components/molecules/inputs/mg-input-numeric/test/mg-input-numeric.spec.js +55 -0
  22. package/dist/collection/components/molecules/inputs/mg-input-numeric/test/mg-input-numeric.spec.js.map +1 -1
  23. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +83 -10
  24. package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
  25. package/dist/collection/components/molecules/inputs/mg-input-password/test/mg-input-password.spec.js +55 -0
  26. package/dist/collection/components/molecules/inputs/mg-input-password/test/mg-input-password.spec.js.map +1 -1
  27. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +82 -9
  28. package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
  29. package/dist/collection/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.js +60 -0
  30. package/dist/collection/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.js.map +1 -1
  31. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +82 -9
  32. package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
  33. package/dist/collection/components/molecules/inputs/mg-input-select/test/mg-input-select.spec.js +55 -0
  34. package/dist/collection/components/molecules/inputs/mg-input-select/test/mg-input-select.spec.js.map +1 -1
  35. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +94 -21
  36. package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
  37. package/dist/collection/components/molecules/inputs/mg-input-text/test/mg-input-text.spec.js +68 -5
  38. package/dist/collection/components/molecules/inputs/mg-input-text/test/mg-input-text.spec.js.map +1 -1
  39. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +100 -26
  40. package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
  41. package/dist/collection/components/molecules/inputs/mg-input-textarea/test/mg-input-textarea.spec.js +67 -4
  42. package/dist/collection/components/molecules/inputs/mg-input-textarea/test/mg-input-textarea.spec.js.map +1 -1
  43. package/dist/collection/components/molecules/mg-form/mg-form.js +2 -2
  44. package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
  45. package/dist/collection/components/molecules/mg-panel/mg-panel.js +8 -6
  46. package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
  47. package/dist/collection/components/molecules/mg-panel/test/mg-panel.e2e.playwright.js +1 -1
  48. package/dist/collection/components/molecules/mg-panel/test/mg-panel.e2e.playwright.js.map +1 -1
  49. package/dist/collection/components/molecules/mg-panel/test/mg-panel.spec.js +3 -13
  50. package/dist/collection/components/molecules/mg-panel/test/mg-panel.spec.js.map +1 -1
  51. package/dist/collection/components/molecules/mg-popover/mg-popover.js +34 -14
  52. package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
  53. package/dist/collection/components/molecules/mg-popover/test/mg-popover.e2e.js +13 -2
  54. package/dist/collection/components/molecules/mg-popover/test/mg-popover.e2e.js.map +1 -1
  55. package/dist/collection/components/molecules/mg-popover/test/mg-popover.spec.js +12 -0
  56. package/dist/collection/components/molecules/mg-popover/test/mg-popover.spec.js.map +1 -1
  57. package/dist/collection/utils/components.utils.js +6 -0
  58. package/dist/collection/utils/components.utils.js.map +1 -1
  59. package/dist/collection/utils/components.utils.spec.js +9 -1
  60. package/dist/collection/utils/components.utils.spec.js.map +1 -1
  61. package/dist/components/components.utils.js +7 -1
  62. package/dist/components/components.utils.js.map +1 -1
  63. package/dist/components/mg-form.js +1 -1
  64. package/dist/components/mg-form.js.map +1 -1
  65. package/dist/components/mg-input-checkbox.js +52 -13
  66. package/dist/components/mg-input-checkbox.js.map +1 -1
  67. package/dist/components/mg-input-date.js +41 -8
  68. package/dist/components/mg-input-date.js.map +1 -1
  69. package/dist/components/mg-input-numeric.js +71 -38
  70. package/dist/components/mg-input-numeric.js.map +1 -1
  71. package/dist/components/mg-input-password.js +45 -10
  72. package/dist/components/mg-input-password.js.map +1 -1
  73. package/dist/components/mg-input-radio.js +44 -9
  74. package/dist/components/mg-input-radio.js.map +1 -1
  75. package/dist/components/mg-input-select2.js +44 -9
  76. package/dist/components/mg-input-select2.js.map +1 -1
  77. package/dist/components/mg-input-text2.js +56 -23
  78. package/dist/components/mg-input-text2.js.map +1 -1
  79. package/dist/components/mg-input-textarea.js +60 -26
  80. package/dist/components/mg-input-textarea.js.map +1 -1
  81. package/dist/components/mg-panel.js +8 -7
  82. package/dist/components/mg-panel.js.map +1 -1
  83. package/dist/components/mg-popover2.js +33 -14
  84. package/dist/components/mg-popover2.js.map +1 -1
  85. package/dist/components/mg-tooltip2.js +30 -11
  86. package/dist/components/mg-tooltip2.js.map +1 -1
  87. package/dist/esm/loader.js +1 -1
  88. package/dist/esm/mg-action-more_34.entry.js +464 -157
  89. package/dist/esm/mg-action-more_34.entry.js.map +1 -1
  90. package/dist/esm/mg-components.js +1 -1
  91. package/dist/mg-components/mg-components.esm.js +1 -1
  92. package/dist/mg-components/mg-components.esm.js.map +1 -1
  93. package/dist/mg-components/p-ff3ca349.entry.js +2 -0
  94. package/dist/mg-components/p-ff3ca349.entry.js.map +1 -0
  95. package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +2 -1
  96. package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +22 -1
  97. package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +17 -2
  98. package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +35 -20
  99. package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +16 -1
  100. package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +16 -1
  101. package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +16 -1
  102. package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +17 -5
  103. package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +17 -5
  104. package/dist/types/components/molecules/mg-form/mg-form.d.ts +1 -1
  105. package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +1 -1
  106. package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -0
  107. package/dist/types/components.d.ts +59 -11
  108. package/dist/types/utils/components.utils.d.ts +6 -0
  109. package/package.json +1 -1
  110. package/dist/mg-components/p-caafc9cf.entry.js +0 -2
  111. package/dist/mg-components/p-caafc9cf.entry.js.map +0 -1
@@ -152,6 +152,12 @@ const getChildWindows = (localWindow, windows = []) => {
152
152
  }
153
153
  return windows;
154
154
  };
155
+ /**
156
+ * Validate string
157
+ * @param value - value to check
158
+ * @returns if string is valid
159
+ */
160
+ const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
155
161
 
156
162
  const mgActionMoreCss = ".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}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}:host{--mg-popover-padding-vertical:1rem;--mg-popover-padding-horizontal:0;--mg-popover-max-width:unset}.mg-action-more__chevron{transition:200ms}.mg-action-more__chevron--rotate.mg-action-more__chevron{transform:rotate(180deg)}";
157
163
 
@@ -795,7 +801,7 @@ const MgForm = class {
795
801
  this.setRequiredMessage();
796
802
  }
797
803
  /**
798
- * Public method to display errors
804
+ * Display input error if it exists.
799
805
  */
800
806
  async displayError() {
801
807
  if (!this.readonly) {
@@ -1590,6 +1596,7 @@ const MgInputCheckbox = class {
1590
1596
  this.inputValid = index.createEvent(this, "input-valid", 7);
1591
1597
  // hasDisplayedError (triggered by blur event)
1592
1598
  this.hasDisplayedError = false;
1599
+ this.mode = 'custom';
1593
1600
  // style
1594
1601
  this.baseClassName = 'mg-input--checkbox';
1595
1602
  // "multi" setup
@@ -1689,10 +1696,7 @@ const MgInputCheckbox = class {
1689
1696
  * Check if input is valid
1690
1697
  */
1691
1698
  this.checkValidity = () => {
1692
- this.valid = this.readonly || this.disabled || (this.getInvalidElement() === undefined && this.validateRequired());
1693
- this.invalid = !this.valid;
1694
- // We need to send valid event even if it is the same value
1695
- this.inputValid.emit(this.valid);
1699
+ this.setValidity(this.readonly || this.disabled || (this.getInvalidElement() === undefined && this.validateRequired()));
1696
1700
  };
1697
1701
  /**
1698
1702
  * Render button text
@@ -1710,12 +1714,17 @@ const MgInputCheckbox = class {
1710
1714
  /**
1711
1715
  * Set input error message
1712
1716
  * @param displayError - dispay error condition
1717
+ * @param errorMessage - errorMessage override
1713
1718
  */
1714
- this.setErrorMessage = (displayError = true) => {
1719
+ this.setErrorMessage = (displayError = true, errorMessage) => {
1715
1720
  // Set error message
1716
1721
  this.errorMessage = undefined;
1717
- if (displayError && !this.valid && !this.validateRequired())
1718
- this.errorMessage = this.messages.errors.required;
1722
+ if (displayError && !this.valid) {
1723
+ if (errorMessage !== undefined)
1724
+ this.errorMessage = errorMessage;
1725
+ else if (!this.validateRequired())
1726
+ this.errorMessage = this.messages.errors.required;
1727
+ }
1719
1728
  };
1720
1729
  /**
1721
1730
  * Method to get mg-popover identifier
@@ -1728,7 +1737,7 @@ const MgInputCheckbox = class {
1728
1737
  */
1729
1738
  this.getDisplayItems = () => (this.searchValue.length > 0 ? this.searchResults : this.checkboxItems);
1730
1739
  this.value = undefined;
1731
- this.type = checkboxTypes[0];
1740
+ this.type = undefined;
1732
1741
  this.identifier = undefined;
1733
1742
  this.name = this.identifier;
1734
1743
  this.label = undefined;
@@ -1769,9 +1778,13 @@ const MgInputCheckbox = class {
1769
1778
  }
1770
1779
  }
1771
1780
  validateType(newValue) {
1772
- if (!checkboxTypes.includes(newValue)) {
1781
+ if (newValue !== undefined && !checkboxTypes.includes(newValue)) {
1773
1782
  throw new Error('<mg-input-checkbox> prop "type" must be a CheckboxType.');
1774
1783
  }
1784
+ else if (newValue === undefined) {
1785
+ this.mode = 'auto';
1786
+ this.type = checkboxTypes[0];
1787
+ }
1775
1788
  else {
1776
1789
  const className = `${this.baseClassName}-multi`;
1777
1790
  if (newValue === 'multi') {
@@ -1803,9 +1816,9 @@ const MgInputCheckbox = class {
1803
1816
  this.classCollection.delete(className);
1804
1817
  }
1805
1818
  validateCheckboxItems(newValue) {
1806
- if (newValue.length > this.multiStart)
1819
+ if (this.mode === 'auto' && newValue.length > this.multiStart)
1807
1820
  this.type = 'multi';
1808
- if (newValue.length > this.searchStart) {
1821
+ if (this.mode === 'auto' || (this.type === 'multi' && newValue.length > this.searchStart)) {
1809
1822
  this.displaySearchInput = this.type === 'multi';
1810
1823
  // refresh search values
1811
1824
  this.updateSearchResults();
@@ -1816,13 +1829,44 @@ const MgInputCheckbox = class {
1816
1829
  this.updateSearchResults();
1817
1830
  }
1818
1831
  /**
1819
- * Public method to display errors
1832
+ * Display input error if it exists.
1820
1833
  */
1821
1834
  async displayError() {
1822
1835
  this.checkValidity();
1823
1836
  this.setErrorMessage();
1824
1837
  this.hasDisplayedError = this.invalid;
1825
1838
  }
1839
+ /**
1840
+ * Set an error and display a custom error message.
1841
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
1842
+ * It must be paired with an error message to display for the given context.
1843
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
1844
+ * @param valid - value indicating the validity
1845
+ * @param errorMessage - the error message to display
1846
+ */
1847
+ async setError(valid, errorMessage) {
1848
+ if (typeof valid !== 'boolean') {
1849
+ throw new Error('<mg-input-checkbox> method "setError()" param "valid" must be a boolean');
1850
+ }
1851
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
1852
+ throw new Error('<mg-input-checkbox> method "setError()" param "errorMessage" must be a string');
1853
+ }
1854
+ else {
1855
+ this.setValidity(valid);
1856
+ this.setErrorMessage(undefined, valid ? undefined : errorMessage);
1857
+ this.hasDisplayedError = this.invalid;
1858
+ }
1859
+ }
1860
+ /**
1861
+ * Method to set validity values
1862
+ * @param newValue - valid new value
1863
+ */
1864
+ setValidity(newValue) {
1865
+ this.valid = newValue;
1866
+ this.invalid = !this.valid;
1867
+ // We need to send valid event even if it is the same value
1868
+ this.inputValid.emit(this.valid);
1869
+ }
1826
1870
  /**
1827
1871
  * Update ckecboxes item
1828
1872
  * @param key - property to update
@@ -2079,10 +2123,7 @@ const MgInputDate = class {
2079
2123
  */
2080
2124
  this.checkValidity = () => {
2081
2125
  var _a;
2082
- this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
2083
- this.invalid = !this.valid;
2084
- // We need to send valid event even if it is the same value
2085
- this.inputValid.emit(this.valid);
2126
+ this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
2086
2127
  };
2087
2128
  /**
2088
2129
  * get input error code
@@ -2111,15 +2152,19 @@ const MgInputDate = class {
2111
2152
  };
2112
2153
  /**
2113
2154
  * Check input errors
2155
+ * @param errorMessage - errorMessage override
2114
2156
  */
2115
- this.setErrorMessage = () => {
2157
+ this.setErrorMessage = (errorMessage) => {
2116
2158
  var _a;
2117
2159
  // Set error message
2118
2160
  this.errorMessage = undefined;
2119
2161
  if (!this.valid) {
2120
2162
  const inputError = this.getInputError();
2163
+ if (errorMessage !== undefined) {
2164
+ this.errorMessage = errorMessage;
2165
+ }
2121
2166
  // required
2122
- if (inputError === InputError$1.REQUIRED) {
2167
+ else if (inputError === InputError$1.REQUIRED) {
2123
2168
  this.errorMessage = this.messages.errors[inputError];
2124
2169
  }
2125
2170
  // min, max & minMax
@@ -2178,13 +2223,44 @@ const MgInputDate = class {
2178
2223
  }
2179
2224
  }
2180
2225
  /**
2181
- * Public method to display errors
2226
+ * Display input error if it exists.
2182
2227
  */
2183
2228
  async displayError() {
2184
2229
  this.checkValidity();
2185
2230
  this.setErrorMessage();
2186
2231
  this.hasDisplayedError = this.invalid;
2187
2232
  }
2233
+ /**
2234
+ * Set an error and display a custom error message.
2235
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
2236
+ * It must be paired with an error message to display for the given context.
2237
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
2238
+ * @param valid - value indicating the validity
2239
+ * @param errorMessage - the error message to display
2240
+ */
2241
+ async setError(valid, errorMessage) {
2242
+ if (typeof valid !== 'boolean') {
2243
+ throw new Error('<mg-input-date> method "setError()" param "valid" must be a boolean');
2244
+ }
2245
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
2246
+ throw new Error('<mg-input-date> method "setError()" param "errorMessage" must be a string');
2247
+ }
2248
+ else {
2249
+ this.setValidity(valid);
2250
+ this.setErrorMessage(valid ? undefined : errorMessage);
2251
+ this.hasDisplayedError = this.invalid;
2252
+ }
2253
+ }
2254
+ /**
2255
+ * Method to set validity values
2256
+ * @param newValue - valid new value
2257
+ */
2258
+ setValidity(newValue) {
2259
+ this.valid = newValue;
2260
+ this.invalid = !this.valid;
2261
+ // We need to send valid event even if it is the same value
2262
+ this.inputValid.emit(this.valid);
2263
+ }
2188
2264
  /*************
2189
2265
  * Lifecycle *
2190
2266
  *************/
@@ -2282,20 +2358,21 @@ const MgInputNumeric = class {
2282
2358
  * Check if input is valid
2283
2359
  */
2284
2360
  this.checkValidity = () => {
2285
- this.valid = this.readonly || this.disabled || this.getInputError() === null;
2286
- this.invalid = !this.valid;
2287
- // We need to send valid event even if it is the same value
2288
- this.inputValid.emit(this.valid);
2361
+ this.setValidity(this.readonly || this.disabled || this.getInputError() === null);
2289
2362
  };
2290
2363
  /**
2291
2364
  * Set input error message
2365
+ * @param errorMessage - errorMessage override
2292
2366
  */
2293
- this.setErrorMessage = () => {
2367
+ this.setErrorMessage = (errorMessage) => {
2294
2368
  // Set error message
2295
2369
  this.errorMessage = undefined;
2296
2370
  if (!this.valid) {
2297
2371
  const inputError = this.getInputError();
2298
- if (inputError === InputError.REQUIRED) {
2372
+ if (errorMessage !== undefined) {
2373
+ this.errorMessage = errorMessage;
2374
+ }
2375
+ else if (inputError === InputError.REQUIRED) {
2299
2376
  this.errorMessage = this.messages.errors[inputError];
2300
2377
  }
2301
2378
  else {
@@ -2389,36 +2466,6 @@ const MgInputNumeric = class {
2389
2466
  this.updateValues(newValue);
2390
2467
  }
2391
2468
  }
2392
- /**
2393
- * Checks if the given value is valid according to the defined rules.
2394
- * @param value - The input value to validate.
2395
- * @param regex - The regular expression for validation.
2396
- * @param integer - The integer part of the value.
2397
- * @param decimal - The decimal part of the value.
2398
- * @returns Returns true if the value is valid, otherwise false.
2399
- */
2400
- isValidValue(value, regex, integer, decimal) {
2401
- return ['', '-'].includes(value) || (value.match(regex) && integer.length <= this.integerLength && decimal.length <= (this.type === 'integer' ? 0 : this.decimalLength));
2402
- }
2403
- /**
2404
- * Handles invalid input values and returns a corrected value.
2405
- * @returns The corrected value.
2406
- */
2407
- handleInvalidValue() {
2408
- return this.storedValue !== undefined ? this.storedValue : null;
2409
- }
2410
- /**
2411
- * Updates the component values based on the validated input value.
2412
- * @param newValue - The validated input value.
2413
- */
2414
- updateValues(newValue) {
2415
- this.value = newValue;
2416
- if (this.input !== undefined)
2417
- this.input.value = this.value;
2418
- this.numericValue = !['', null].includes(this.value) ? parseFloat(this.value.replace(',', '.')) : null;
2419
- this.valueChange.emit(this.numericValue);
2420
- this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
2421
- }
2422
2469
  handleValidityChange(newValue, _oldValue, prop) {
2423
2470
  if (this.input !== undefined) {
2424
2471
  this.input[prop] = newValue;
@@ -2445,13 +2492,74 @@ const MgInputNumeric = class {
2445
2492
  }
2446
2493
  }
2447
2494
  /**
2448
- * Public method to display errors
2495
+ * Display input error if it exists.
2449
2496
  */
2450
2497
  async displayError() {
2451
2498
  this.checkValidity();
2452
2499
  this.setErrorMessage();
2453
2500
  this.hasDisplayedError = this.invalid;
2454
2501
  }
2502
+ /**
2503
+ * Set an error and display a custom error message.
2504
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
2505
+ * It must be paired with an error message to display for the given context.
2506
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
2507
+ * @param valid - value indicating the validity
2508
+ * @param errorMessage - the error message to display
2509
+ */
2510
+ async setError(valid, errorMessage) {
2511
+ if (typeof valid !== 'boolean') {
2512
+ throw new Error('<mg-input-numeric> method "setError()" param "valid" must be a boolean');
2513
+ }
2514
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
2515
+ throw new Error('<mg-input-numeric> method "setError()" param "errorMessage" must be a string');
2516
+ }
2517
+ else {
2518
+ this.setValidity(valid);
2519
+ this.setErrorMessage(valid ? undefined : errorMessage);
2520
+ this.hasDisplayedError = this.invalid;
2521
+ }
2522
+ }
2523
+ /**
2524
+ * Method to set validity values
2525
+ * @param newValue - valid new value
2526
+ */
2527
+ setValidity(newValue) {
2528
+ this.valid = newValue;
2529
+ this.invalid = !this.valid;
2530
+ // We need to send valid event even if it is the same value
2531
+ this.inputValid.emit(this.valid);
2532
+ }
2533
+ /**
2534
+ * Checks if the given value is valid according to the defined rules.
2535
+ * @param value - The input value to validate.
2536
+ * @param regex - The regular expression for validation.
2537
+ * @param integer - The integer part of the value.
2538
+ * @param decimal - The decimal part of the value.
2539
+ * @returns Returns true if the value is valid, otherwise false.
2540
+ */
2541
+ isValidValue(value, regex, integer, decimal) {
2542
+ return ['', '-'].includes(value) || (value.match(regex) && integer.length <= this.integerLength && decimal.length <= (this.type === 'integer' ? 0 : this.decimalLength));
2543
+ }
2544
+ /**
2545
+ * Handles invalid input values and returns a corrected value.
2546
+ * @returns The corrected value.
2547
+ */
2548
+ handleInvalidValue() {
2549
+ return this.storedValue !== undefined ? this.storedValue : null;
2550
+ }
2551
+ /**
2552
+ * Updates the component values based on the validated input value.
2553
+ * @param newValue - The validated input value.
2554
+ */
2555
+ updateValues(newValue) {
2556
+ this.value = newValue;
2557
+ if (this.input !== undefined)
2558
+ this.input.value = this.value;
2559
+ this.numericValue = !['', null].includes(this.value) ? parseFloat(this.value.replace(',', '.')) : null;
2560
+ this.valueChange.emit(this.numericValue);
2561
+ this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
2562
+ }
2455
2563
  /**
2456
2564
  * Displayed value in input
2457
2565
  * Change on focus/blur
@@ -2539,20 +2647,23 @@ const MgInputPassword = class {
2539
2647
  */
2540
2648
  this.checkValidity = () => {
2541
2649
  var _a;
2542
- this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
2543
- this.invalid = !this.valid;
2544
- // We need to send valid event even if it is the same value
2545
- this.inputValid.emit(this.valid);
2650
+ this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
2546
2651
  };
2547
2652
  /**
2548
2653
  * Set input error message
2654
+ * @param errorMessage - errorMessage override
2549
2655
  */
2550
- this.setErrorMessage = () => {
2656
+ this.setErrorMessage = (errorMessage) => {
2551
2657
  // Set error message
2552
2658
  this.errorMessage = undefined;
2553
- // required
2554
- if (!this.valid && this.input.validity.valueMissing) {
2555
- this.errorMessage = this.messages.errors.required;
2659
+ if (!this.valid) {
2660
+ if (errorMessage !== undefined) {
2661
+ this.errorMessage = errorMessage;
2662
+ }
2663
+ // required
2664
+ else if (this.input.validity.valueMissing) {
2665
+ this.errorMessage = this.messages.errors.required;
2666
+ }
2556
2667
  }
2557
2668
  };
2558
2669
  this.value = undefined;
@@ -2587,13 +2698,44 @@ const MgInputPassword = class {
2587
2698
  }
2588
2699
  }
2589
2700
  /**
2590
- * Public method to display errors
2701
+ * Display input error if it exists.
2591
2702
  */
2592
2703
  async displayError() {
2593
2704
  this.checkValidity();
2594
2705
  this.setErrorMessage();
2595
2706
  this.hasDisplayedError = this.invalid;
2596
2707
  }
2708
+ /**
2709
+ * Set an error and display a custom error message.
2710
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
2711
+ * It must be paired with an error message to display for the given context.
2712
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
2713
+ * @param valid - value indicating the validity
2714
+ * @param errorMessage - the error message to display
2715
+ */
2716
+ async setError(valid, errorMessage) {
2717
+ if (typeof valid !== 'boolean') {
2718
+ throw new Error('<mg-input-password> method "setError()" param "valid" must be a boolean');
2719
+ }
2720
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
2721
+ throw new Error('<mg-input-password> method "setError()" param "errorMessage" must be a string');
2722
+ }
2723
+ else {
2724
+ this.setValidity(valid);
2725
+ this.setErrorMessage(valid ? undefined : errorMessage);
2726
+ this.hasDisplayedError = this.invalid;
2727
+ }
2728
+ }
2729
+ /**
2730
+ * Method to set validity values
2731
+ * @param newValue - valid new value
2732
+ */
2733
+ setValidity(newValue) {
2734
+ this.valid = newValue;
2735
+ this.invalid = !this.valid;
2736
+ // We need to send valid event even if it is the same value
2737
+ this.inputValid.emit(this.valid);
2738
+ }
2597
2739
  /*************
2598
2740
  * Lifecycle *
2599
2741
  *************/
@@ -2670,20 +2812,23 @@ const MgInputRadio = class {
2670
2812
  * Check if input is valid
2671
2813
  */
2672
2814
  this.checkValidity = () => {
2673
- this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
2674
- this.invalid = !this.valid;
2675
- // We need to send valid event even if it is the same value
2676
- this.inputValid.emit(this.valid);
2815
+ this.setValidity(this.readonly || this.disabled || this.getInvalidElement() === undefined);
2677
2816
  };
2678
2817
  /**
2679
2818
  * Set input error message
2819
+ * @param errorMessage - errorMessage override
2680
2820
  */
2681
- this.setErrorMessage = () => {
2821
+ this.setErrorMessage = (errorMessage) => {
2682
2822
  const invalidElement = this.getInvalidElement();
2683
2823
  // Set error message
2684
2824
  this.errorMessage = undefined;
2685
- if (!this.valid && invalidElement.validity.valueMissing) {
2686
- this.errorMessage = this.messages.errors.required;
2825
+ if (!this.valid) {
2826
+ if (errorMessage !== undefined) {
2827
+ this.errorMessage = errorMessage;
2828
+ }
2829
+ else if (invalidElement.validity.valueMissing) {
2830
+ this.errorMessage = this.messages.errors.required;
2831
+ }
2687
2832
  }
2688
2833
  };
2689
2834
  /**
@@ -2741,13 +2886,44 @@ const MgInputRadio = class {
2741
2886
  }
2742
2887
  }
2743
2888
  /**
2744
- * Public method to display errors
2889
+ * Display input error if it exists.
2745
2890
  */
2746
2891
  async displayError() {
2747
2892
  this.checkValidity();
2748
2893
  this.setErrorMessage();
2749
2894
  this.hasDisplayedError = this.invalid;
2750
2895
  }
2896
+ /**
2897
+ * Set an error and display a custom error message.
2898
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
2899
+ * It must be paired with an error message to display for the given context.
2900
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
2901
+ * @param valid - value indicating the validity
2902
+ * @param errorMessage - the error message to display
2903
+ */
2904
+ async setError(valid, errorMessage) {
2905
+ if (typeof valid !== 'boolean') {
2906
+ throw new Error('<mg-input-radio> method "setError()" param "valid" must be a boolean');
2907
+ }
2908
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
2909
+ throw new Error('<mg-input-radio> method "setError()" param "errorMessage" must be a string');
2910
+ }
2911
+ else {
2912
+ this.setValidity(valid);
2913
+ this.setErrorMessage(valid ? undefined : errorMessage);
2914
+ this.hasDisplayedError = this.invalid;
2915
+ }
2916
+ }
2917
+ /**
2918
+ * Method to set validity values
2919
+ * @param newValue - valid new value
2920
+ */
2921
+ setValidity(newValue) {
2922
+ this.valid = newValue;
2923
+ this.invalid = !this.valid;
2924
+ // We need to send valid event even if it is the same value
2925
+ this.inputValid.emit(this.valid);
2926
+ }
2751
2927
  /*************
2752
2928
  * Lifecycle *
2753
2929
  *************/
@@ -2896,19 +3072,22 @@ const MgInputSelect = class {
2896
3072
  */
2897
3073
  this.checkValidity = () => {
2898
3074
  var _a;
2899
- this.valid = !this.isDisabledValue() && (this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
2900
- this.invalid = !this.valid;
2901
- // We need to send valid event even if it is the same value
2902
- this.inputValid.emit(this.valid);
3075
+ this.setValidity(!this.isDisabledValue() && (this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true)));
2903
3076
  };
2904
3077
  /**
2905
3078
  * Set input error message
3079
+ * @param errorMessage - errorMessage override
2906
3080
  */
2907
- this.setErrorMessage = () => {
3081
+ this.setErrorMessage = (errorMessage) => {
2908
3082
  // Set error message
2909
3083
  this.errorMessage = undefined;
2910
- if (!this.valid && this.input.validity.valueMissing) {
2911
- this.errorMessage = this.messages.errors.required;
3084
+ if (!this.valid) {
3085
+ if (errorMessage !== undefined) {
3086
+ this.errorMessage = errorMessage;
3087
+ }
3088
+ else if (this.input.validity.valueMissing) {
3089
+ this.errorMessage = this.messages.errors.required;
3090
+ }
2912
3091
  }
2913
3092
  };
2914
3093
  /**
@@ -2992,13 +3171,44 @@ const MgInputSelect = class {
2992
3171
  }
2993
3172
  }
2994
3173
  /**
2995
- * Public method to display errors
3174
+ * Display input error if it exists.
2996
3175
  */
2997
3176
  async displayError() {
2998
3177
  this.checkValidity();
2999
3178
  this.setErrorMessage();
3000
3179
  this.hasDisplayedError = this.invalid;
3001
3180
  }
3181
+ /**
3182
+ * Set an error and display a custom error message.
3183
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
3184
+ * It must be paired with an error message to display for the given context.
3185
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
3186
+ * @param valid - value indicating the validity
3187
+ * @param errorMessage - the error message to display
3188
+ */
3189
+ async setError(valid, errorMessage) {
3190
+ if (typeof valid !== 'boolean') {
3191
+ throw new Error('<mg-input-select> method "setError()" param "valid" must be a boolean');
3192
+ }
3193
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
3194
+ throw new Error('<mg-input-select> method "setError()" param "errorMessage" must be a string');
3195
+ }
3196
+ else {
3197
+ this.setValidity(valid);
3198
+ this.setErrorMessage(valid ? undefined : errorMessage);
3199
+ this.hasDisplayedError = this.invalid;
3200
+ }
3201
+ }
3202
+ /**
3203
+ * Method to set validity values
3204
+ * @param newValue - valid new value
3205
+ */
3206
+ setValidity(newValue) {
3207
+ this.valid = newValue;
3208
+ this.invalid = !this.valid;
3209
+ // We need to send valid event even if it is the same value
3210
+ this.inputValid.emit(this.valid);
3211
+ }
3002
3212
  /*************
3003
3213
  * Lifecycle *
3004
3214
  *************/
@@ -3093,19 +3303,21 @@ const MgInputText = class {
3093
3303
  */
3094
3304
  this.checkValidity = () => {
3095
3305
  var _a;
3096
- this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true);
3097
- this.invalid = !this.valid;
3098
- // We need to send valid event even if it is the same value
3099
- this.inputValid.emit(this.valid);
3306
+ this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
3100
3307
  };
3101
3308
  /**
3102
3309
  * Set input error message
3310
+ * @param errorMessage - errorMessage override
3103
3311
  */
3104
- this.setErrorMessage = () => {
3312
+ this.setErrorMessage = (errorMessage) => {
3105
3313
  // Set error message
3106
3314
  this.errorMessage = undefined;
3315
+ // Does have a custom error message
3316
+ if (!this.valid && errorMessage !== undefined) {
3317
+ this.errorMessage = errorMessage;
3318
+ }
3107
3319
  // Does not match pattern
3108
- if (!this.valid && this.input.validity.patternMismatch) {
3320
+ else if (!this.valid && this.input.validity.patternMismatch) {
3109
3321
  this.errorMessage = this.patternErrorMessage;
3110
3322
  }
3111
3323
  // required
@@ -3113,17 +3325,6 @@ const MgInputText = class {
3113
3325
  this.errorMessage = this.messages.errors.required;
3114
3326
  }
3115
3327
  };
3116
- /**
3117
- * Validate pattern configuration
3118
- */
3119
- this.validatePattern = () => {
3120
- if (this.pattern !== undefined &&
3121
- typeof this.pattern === 'string' &&
3122
- this.pattern !== '' &&
3123
- (this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
3124
- throw new Error('<mg-input-text> prop "pattern" must be paired with the prop "patternErrorMessage"');
3125
- }
3126
- };
3127
3328
  /**
3128
3329
  * Validate append slot
3129
3330
  */
@@ -3182,6 +3383,11 @@ const MgInputText = class {
3182
3383
  }
3183
3384
  }
3184
3385
  }
3386
+ validatePattern(newValue) {
3387
+ if (newValue !== undefined && !(isValidString(this.pattern) && isValidString(this.patternErrorMessage))) {
3388
+ throw new Error('<mg-input-text> props "pattern" and "patternErrorMessage" must be non-empty string and paired.');
3389
+ }
3390
+ }
3185
3391
  /**
3186
3392
  * Public method to play input focus
3187
3393
  */
@@ -3189,13 +3395,44 @@ const MgInputText = class {
3189
3395
  this.input.focus();
3190
3396
  }
3191
3397
  /**
3192
- * Public method to display errors
3398
+ * Display input error if it exists.
3193
3399
  */
3194
3400
  async displayError() {
3195
3401
  this.checkValidity();
3196
3402
  this.setErrorMessage();
3197
3403
  this.hasDisplayedError = this.invalid;
3198
3404
  }
3405
+ /**
3406
+ * Set an error and display a custom error message.
3407
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
3408
+ * It must be paired with an error message to display for the given context.
3409
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
3410
+ * @param valid - value indicating the validity
3411
+ * @param errorMessage - the error message to display
3412
+ */
3413
+ async setError(valid, errorMessage) {
3414
+ if (typeof valid !== 'boolean') {
3415
+ throw new Error('<mg-input-text> method "setError()" param "valid" must be a boolean');
3416
+ }
3417
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
3418
+ throw new Error('<mg-input-text> method "setError()" param "errorMessage" must be a string');
3419
+ }
3420
+ else {
3421
+ this.setValidity(valid);
3422
+ this.setErrorMessage(valid ? undefined : errorMessage);
3423
+ this.hasDisplayedError = this.invalid;
3424
+ }
3425
+ }
3426
+ /**
3427
+ * Method to set validity values
3428
+ * @param newValue - valid new value
3429
+ */
3430
+ setValidity(newValue) {
3431
+ this.valid = newValue;
3432
+ this.invalid = !this.valid;
3433
+ // We need to send valid event even if it is the same value
3434
+ this.inputValid.emit(this.valid);
3435
+ }
3199
3436
  /*************
3200
3437
  * Lifecycle *
3201
3438
  *************/
@@ -3209,7 +3446,8 @@ const MgInputText = class {
3209
3446
  this.characterLeftId = `${this.identifier}-character-left`;
3210
3447
  // Validate
3211
3448
  this.validateIcon(this.icon);
3212
- this.validatePattern();
3449
+ this.validatePattern(this.pattern);
3450
+ this.validatePattern(this.patternErrorMessage);
3213
3451
  this.validateAppendSlot();
3214
3452
  // Check validity when component is ready
3215
3453
  // return a promise to process action only in the FIRST render().
@@ -3238,7 +3476,9 @@ const MgInputText = class {
3238
3476
  "icon": ["validateIcon"],
3239
3477
  "required": ["handleValidityChange"],
3240
3478
  "readonly": ["handleValidityChange"],
3241
- "disabled": ["handleValidityChange"]
3479
+ "disabled": ["handleValidityChange"],
3480
+ "pattern": ["validatePattern"],
3481
+ "patternErrorMessage": ["validatePattern"]
3242
3482
  }; }
3243
3483
  };
3244
3484
  MgInputText.style = mgInputTextCss;
@@ -3296,35 +3536,27 @@ const MgInputTextarea = class {
3296
3536
  */
3297
3537
  this.checkValidity = () => {
3298
3538
  var _a;
3299
- this.valid = this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity());
3300
- this.invalid = !this.valid;
3301
- // We need to send valid event even if it is the same value
3302
- this.inputValid.emit(this.valid);
3539
+ this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity()));
3303
3540
  };
3304
3541
  /**
3305
3542
  * Set input error message
3543
+ * @param errorMessage - errorMessage override
3306
3544
  */
3307
- this.setErrorMessage = () => {
3545
+ this.setErrorMessage = (errorMessage) => {
3308
3546
  // Set error message
3309
3547
  this.errorMessage = undefined;
3310
3548
  // Does not match pattern
3311
- if (!this.valid && !this.getPatternValidity()) {
3312
- this.errorMessage = this.patternErrorMessage;
3313
- }
3314
- // required
3315
- else if (!this.valid && this.input.validity.valueMissing) {
3316
- this.errorMessage = this.messages.errors.required;
3317
- }
3318
- };
3319
- /**
3320
- * Validate pattern configuration
3321
- */
3322
- this.validatePattern = () => {
3323
- if (this.pattern !== undefined &&
3324
- typeof this.pattern === 'string' &&
3325
- this.pattern !== '' &&
3326
- (this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
3327
- throw new Error('<mg-input-textarea> prop "pattern" must be paired with the prop "patternErrorMessage"');
3549
+ if (!this.valid) {
3550
+ if (errorMessage !== undefined) {
3551
+ this.errorMessage = errorMessage;
3552
+ }
3553
+ else if (!this.getPatternValidity()) {
3554
+ this.errorMessage = this.patternErrorMessage;
3555
+ }
3556
+ // required
3557
+ else if (this.input.validity.valueMissing) {
3558
+ this.errorMessage = this.messages.errors.required;
3559
+ }
3328
3560
  }
3329
3561
  };
3330
3562
  this.value = undefined;
@@ -3365,6 +3597,11 @@ const MgInputTextarea = class {
3365
3597
  }
3366
3598
  }
3367
3599
  }
3600
+ validatePattern(newValue) {
3601
+ if (newValue !== undefined && !(isValidString(this.pattern) && isValidString(this.patternErrorMessage))) {
3602
+ throw new Error('<mg-input-textarea> props "pattern" and "patternErrorMessage" must be non-empty string and paired.');
3603
+ }
3604
+ }
3368
3605
  validateDisplayCharacterLeft(newValue) {
3369
3606
  if (newValue) {
3370
3607
  this.classCollection.add(this.classHasDisplayCharacterLeft);
@@ -3374,13 +3611,44 @@ const MgInputTextarea = class {
3374
3611
  }
3375
3612
  }
3376
3613
  /**
3377
- * Public method to display errors
3614
+ * Display input error if it exists.
3378
3615
  */
3379
3616
  async displayError() {
3380
3617
  this.checkValidity();
3381
3618
  this.setErrorMessage();
3382
3619
  this.hasDisplayedError = this.invalid;
3383
3620
  }
3621
+ /**
3622
+ * Set an error and display a custom error message.
3623
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
3624
+ * It must be paired with an error message to display for the given context.
3625
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
3626
+ * @param valid - value indicating the validity
3627
+ * @param errorMessage - the error message to display
3628
+ */
3629
+ async setError(valid, errorMessage) {
3630
+ if (typeof valid !== 'boolean') {
3631
+ throw new Error('<mg-input-textarea> method "setError()" param "valid" must be a boolean');
3632
+ }
3633
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
3634
+ throw new Error('<mg-input-textarea> method "setError()" param "errorMessage" must be a string');
3635
+ }
3636
+ else {
3637
+ this.setValidity(valid);
3638
+ this.setErrorMessage(valid ? undefined : errorMessage);
3639
+ this.hasDisplayedError = this.invalid;
3640
+ }
3641
+ }
3642
+ /**
3643
+ * Method to set validity values
3644
+ * @param newValue - valid new value
3645
+ */
3646
+ setValidity(newValue) {
3647
+ this.valid = newValue;
3648
+ this.invalid = !this.valid;
3649
+ // We need to send valid event even if it is the same value
3650
+ this.inputValid.emit(this.valid);
3651
+ }
3384
3652
  /*************
3385
3653
  * Lifecycle *
3386
3654
  *************/
@@ -3394,7 +3662,8 @@ const MgInputTextarea = class {
3394
3662
  this.characterLeftId = `${this.identifier}-character-left`;
3395
3663
  // Validate
3396
3664
  this.validateDisplayCharacterLeft(this.displayCharacterLeft);
3397
- this.validatePattern();
3665
+ this.validatePattern(this.pattern);
3666
+ this.validatePattern(this.patternErrorMessage);
3398
3667
  // Check validity when component is ready
3399
3668
  // return a promise to process action only in the FIRST render().
3400
3669
  // https://stenciljs.com/docs/component-lifecycle#componentwillload
@@ -3423,6 +3692,8 @@ const MgInputTextarea = class {
3423
3692
  "required": ["handleValidityChange"],
3424
3693
  "readonly": ["handleValidityChange"],
3425
3694
  "disabled": ["handleValidityChange"],
3695
+ "pattern": ["validatePattern"],
3696
+ "patternErrorMessage": ["validatePattern"],
3426
3697
  "displayCharacterLeft": ["validateDisplayCharacterLeft"]
3427
3698
  }; }
3428
3699
  };
@@ -4699,11 +4970,9 @@ const MgPanel = class {
4699
4970
  throw new Error('<mg-panel> prop "panelTitle" is required.');
4700
4971
  this.titleChange.emit(newValue);
4701
4972
  }
4702
- validatetitlePattern(newValue) {
4973
+ validateTitlePattern(newValue) {
4703
4974
  if (newValue !== undefined && !this.titleEditable)
4704
- throw new Error('<mg-panel> prop "titleEditable" must be set to `true`.');
4705
- if (newValue !== undefined && (this.titlePatternErrorMessage === undefined || this.titlePatternErrorMessage.trim() === ''))
4706
- throw new Error('<mg-panel> prop "titlePattern" must be paired with the prop "titlePatternErrorMessage".');
4975
+ throw new Error(`<mg-panel> prop "titleEditable" must be set to "true".`);
4707
4976
  }
4708
4977
  validateTitlePosition(newValue) {
4709
4978
  if (!titlePositions.includes(newValue))
@@ -4728,7 +4997,8 @@ const MgPanel = class {
4728
4997
  // Get locales
4729
4998
  this.messages = mgMenu_conf.initLocales(this.element).messages;
4730
4999
  // Validate
4731
- this.validatetitlePattern(this.titlePattern);
5000
+ this.validateTitlePattern(this.titlePattern);
5001
+ this.validateTitlePattern(this.titlePatternErrorMessage);
4732
5002
  this.validatePanelTitle(this.panelTitle);
4733
5003
  this.validateExpandToggleDisplay(this.expandToggleDisplay);
4734
5004
  this.validateTitlePosition(this.titlePosition);
@@ -4752,7 +5022,8 @@ const MgPanel = class {
4752
5022
  get element() { return index.getElement(this); }
4753
5023
  static get watchers() { return {
4754
5024
  "panelTitle": ["validatePanelTitle"],
4755
- "titlePattern": ["validatetitlePattern"],
5025
+ "titlePattern": ["validateTitlePattern"],
5026
+ "titlePatternErrorMessage": ["validateTitlePattern"],
4756
5027
  "titlePosition": ["validateTitlePosition"],
4757
5028
  "expanded": ["handleExpanded"],
4758
5029
  "expandToggleDisplay": ["validateExpandToggleDisplay"]
@@ -6612,21 +6883,27 @@ const MgPopover = class {
6612
6883
  * Render popover content element
6613
6884
  */
6614
6885
  this.renderPopoverContent = () => {
6615
- this.mgPopoverContent = document.createElement('mg-popover-content');
6616
- this.mgPopoverContent.setAttribute('slot', 'content');
6617
- this.mgPopoverContent.setAttribute('id', this.identifier);
6618
- this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);
6619
- const arrow = document.createElement('div');
6620
- arrow.setAttribute('slot', 'arrow');
6621
- arrow.dataset.popperArrow = '';
6622
- this.mgPopoverContent.appendChild(arrow);
6623
- // insert elements in DOM
6624
- ['[slot="title"]', '[slot="content"]:not(mg-popover-content)'].forEach(slotType => {
6625
- Array.from(this.element.querySelectorAll(slotType)).forEach(slot => {
6626
- this.mgPopoverContent.appendChild(slot);
6886
+ const mgPopoverContent = this.element.querySelector('mg-popover-content');
6887
+ if (mgPopoverContent === null) {
6888
+ this.mgPopoverContent = document.createElement('mg-popover-content');
6889
+ this.mgPopoverContent.setAttribute('slot', 'content');
6890
+ this.mgPopoverContent.setAttribute('id', this.identifier);
6891
+ this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);
6892
+ const arrow = document.createElement('div');
6893
+ arrow.setAttribute('slot', 'arrow');
6894
+ arrow.dataset.popperArrow = '';
6895
+ this.mgPopoverContent.appendChild(arrow);
6896
+ // insert elements in DOM
6897
+ ['[slot="title"]', '[slot="content"]:not(mg-popover-content)'].forEach(slotType => {
6898
+ Array.from(this.element.querySelectorAll(slotType)).forEach(slot => {
6899
+ this.mgPopoverContent.appendChild(slot);
6900
+ });
6627
6901
  });
6628
- });
6629
- this.element.appendChild(this.mgPopoverContent);
6902
+ this.element.appendChild(this.mgPopoverContent);
6903
+ }
6904
+ else {
6905
+ mgPopoverContent.setAttribute('id', this.identifier);
6906
+ }
6630
6907
  };
6631
6908
  this.identifier = createID('mg-popover');
6632
6909
  this.placement = 'bottom';
@@ -6635,6 +6912,10 @@ const MgPopover = class {
6635
6912
  this.display = false;
6636
6913
  this.disabled = false;
6637
6914
  }
6915
+ validateIdentifier() {
6916
+ // use renderPopoverContent to update popover-content id
6917
+ this.renderPopoverContent();
6918
+ }
6638
6919
  validateArrowHide(newValue) {
6639
6920
  if (newValue)
6640
6921
  this.mgPopoverContent.dataset.arrowHide = '';
@@ -6671,6 +6952,7 @@ const MgPopover = class {
6671
6952
  // render mg-popover-content slot
6672
6953
  this.renderPopoverContent();
6673
6954
  this.validateCloseButton(this.closeButton);
6955
+ this.validateIdentifier();
6674
6956
  this.validateArrowHide(this.arrowHide);
6675
6957
  }
6676
6958
  /**
@@ -6695,6 +6977,12 @@ const MgPopover = class {
6695
6977
  offset: [0, 0],
6696
6978
  },
6697
6979
  },
6980
+ {
6981
+ name: 'flip',
6982
+ options: {
6983
+ fallbackPlacements: ['auto'],
6984
+ },
6985
+ },
6698
6986
  ],
6699
6987
  });
6700
6988
  // add resize observer
@@ -6724,6 +7012,7 @@ const MgPopover = class {
6724
7012
  }
6725
7013
  get element() { return index.getElement(this); }
6726
7014
  static get watchers() { return {
7015
+ "identifier": ["validateIdentifier"],
6727
7016
  "arrowHide": ["validateArrowHide"],
6728
7017
  "closeButton": ["validateCloseButton"],
6729
7018
  "display": ["handleDisplay"]
@@ -7306,6 +7595,12 @@ const MgTooltip = class {
7306
7595
  offset: [0, 8],
7307
7596
  },
7308
7597
  },
7598
+ {
7599
+ name: 'flip',
7600
+ options: {
7601
+ fallbackPlacements: ['auto'],
7602
+ },
7603
+ },
7309
7604
  ],
7310
7605
  });
7311
7606
  // Manage tooltipedElement focus/blur events
@@ -7343,6 +7638,10 @@ const MgTooltip = class {
7343
7638
  this.display = false;
7344
7639
  this.disabled = false;
7345
7640
  }
7641
+ validateIdentifier() {
7642
+ // use renderTooltipContent to update tooltip-content id
7643
+ this.renderTooltipContent();
7644
+ }
7346
7645
  validateMessage(newValue) {
7347
7646
  if (typeof newValue !== 'string' || newValue.trim() === '') {
7348
7647
  throw new Error('<mg-tooltip> prop "message" is required.');
@@ -7368,16 +7667,22 @@ const MgTooltip = class {
7368
7667
  /**
7369
7668
  * Render tooltip content element
7370
7669
  */
7371
- renderTooltip() {
7372
- const mgTooltipContent = document.createElement('mg-tooltip-content');
7373
- mgTooltipContent.setAttribute('slot', 'content');
7374
- mgTooltipContent.setAttribute('id', this.identifier);
7375
- const arrow = document.createElement('div');
7376
- arrow.setAttribute('slot', 'arrow');
7377
- arrow.dataset.popperArrow = '';
7378
- mgTooltipContent.appendChild(arrow);
7379
- // append tooltip element to component
7380
- this.element.appendChild(mgTooltipContent);
7670
+ renderTooltipContent() {
7671
+ const mgTooltipContent = this.element.querySelector('mg-tooltip-content');
7672
+ if (mgTooltipContent === null) {
7673
+ const mgTooltipContent = document.createElement('mg-tooltip-content');
7674
+ mgTooltipContent.setAttribute('slot', 'content');
7675
+ mgTooltipContent.setAttribute('id', this.identifier);
7676
+ const arrow = document.createElement('div');
7677
+ arrow.setAttribute('slot', 'arrow');
7678
+ arrow.dataset.popperArrow = '';
7679
+ mgTooltipContent.appendChild(arrow);
7680
+ // append tooltip element to component
7681
+ this.element.appendChild(mgTooltipContent);
7682
+ }
7683
+ else {
7684
+ mgTooltipContent.setAttribute('id', this.identifier);
7685
+ }
7381
7686
  }
7382
7687
  /*************
7383
7688
  * Lifecycle *
@@ -7389,11 +7694,12 @@ const MgTooltip = class {
7389
7694
  // Get windows to attach events
7390
7695
  this.windows = getWindows(window);
7391
7696
  // Get tooltip element
7392
- this.renderTooltip();
7697
+ this.renderTooltipContent();
7393
7698
  this.mgTooltipContent = this.element.querySelector(`#${this.identifier}`);
7394
7699
  //validate properties
7395
7700
  this.validateDisabled(this.disabled);
7396
7701
  this.validateMessage(this.message);
7702
+ this.validateIdentifier();
7397
7703
  }
7398
7704
  /**
7399
7705
  * Get slotted element
@@ -7441,6 +7747,7 @@ const MgTooltip = class {
7441
7747
  }
7442
7748
  get element() { return index.getElement(this); }
7443
7749
  static get watchers() { return {
7750
+ "identifier": ["validateIdentifier"],
7444
7751
  "message": ["validateMessage"],
7445
7752
  "display": ["handleDisplay"],
7446
7753
  "disabled": ["validateDisabled"]