@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
@@ -39,20 +39,23 @@ export class MgInputRadio {
39
39
  * Check if input is valid
40
40
  */
41
41
  this.checkValidity = () => {
42
- this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;
43
- this.invalid = !this.valid;
44
- // We need to send valid event even if it is the same value
45
- this.inputValid.emit(this.valid);
42
+ this.setValidity(this.readonly || this.disabled || this.getInvalidElement() === undefined);
46
43
  };
47
44
  /**
48
45
  * Set input error message
46
+ * @param errorMessage - errorMessage override
49
47
  */
50
- this.setErrorMessage = () => {
48
+ this.setErrorMessage = (errorMessage) => {
51
49
  const invalidElement = this.getInvalidElement();
52
50
  // Set error message
53
51
  this.errorMessage = undefined;
54
- if (!this.valid && invalidElement.validity.valueMissing) {
55
- this.errorMessage = this.messages.errors.required;
52
+ if (!this.valid) {
53
+ if (errorMessage !== undefined) {
54
+ this.errorMessage = errorMessage;
55
+ }
56
+ else if (invalidElement.validity.valueMissing) {
57
+ this.errorMessage = this.messages.errors.required;
58
+ }
56
59
  }
57
60
  };
58
61
  /**
@@ -110,13 +113,44 @@ export class MgInputRadio {
110
113
  }
111
114
  }
112
115
  /**
113
- * Public method to display errors
116
+ * Display input error if it exists.
114
117
  */
115
118
  async displayError() {
116
119
  this.checkValidity();
117
120
  this.setErrorMessage();
118
121
  this.hasDisplayedError = this.invalid;
119
122
  }
123
+ /**
124
+ * Set an error and display a custom error message.
125
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
126
+ * It must be paired with an error message to display for the given context.
127
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
128
+ * @param valid - value indicating the validity
129
+ * @param errorMessage - the error message to display
130
+ */
131
+ async setError(valid, errorMessage) {
132
+ if (typeof valid !== 'boolean') {
133
+ throw new Error('<mg-input-radio> method "setError()" param "valid" must be a boolean');
134
+ }
135
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
136
+ throw new Error('<mg-input-radio> method "setError()" param "errorMessage" must be a string');
137
+ }
138
+ else {
139
+ this.setValidity(valid);
140
+ this.setErrorMessage(valid ? undefined : errorMessage);
141
+ this.hasDisplayedError = this.invalid;
142
+ }
143
+ }
144
+ /**
145
+ * Method to set validity values
146
+ * @param newValue - valid new value
147
+ */
148
+ setValidity(newValue) {
149
+ this.valid = newValue;
150
+ this.invalid = !this.valid;
151
+ // We need to send valid event even if it is the same value
152
+ this.inputValid.emit(this.valid);
153
+ }
120
154
  /*************
121
155
  * Lifecycle *
122
156
  *************/
@@ -483,9 +517,48 @@ export class MgInputRadio {
483
517
  "return": "Promise<void>"
484
518
  },
485
519
  "docs": {
486
- "text": "Public method to display errors",
520
+ "text": "Display input error if it exists.",
487
521
  "tags": []
488
522
  }
523
+ },
524
+ "setError": {
525
+ "complexType": {
526
+ "signature": "(valid: MgInputRadio['valid'], errorMessage: string) => Promise<void>",
527
+ "parameters": [{
528
+ "tags": [{
529
+ "name": "param",
530
+ "text": "valid - value indicating the validity"
531
+ }],
532
+ "text": "- value indicating the validity"
533
+ }, {
534
+ "tags": [{
535
+ "name": "param",
536
+ "text": "errorMessage - the error message to display"
537
+ }],
538
+ "text": "- the error message to display"
539
+ }],
540
+ "references": {
541
+ "Promise": {
542
+ "location": "global",
543
+ "id": "global::Promise"
544
+ },
545
+ "MgInputRadio": {
546
+ "location": "global",
547
+ "id": "global::MgInputRadio"
548
+ }
549
+ },
550
+ "return": "Promise<void>"
551
+ },
552
+ "docs": {
553
+ "text": "Set an error and display a custom error message.\nThis method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.\nIt must be paired with an error message to display for the given context.\nWhen used to set validity to `false`, you should use this method again to reset the validity to `true`.",
554
+ "tags": [{
555
+ "name": "param",
556
+ "text": "valid - value indicating the validity"
557
+ }, {
558
+ "name": "param",
559
+ "text": "errorMessage - the error message to display"
560
+ }]
561
+ }
489
562
  }
490
563
  };
491
564
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mg-input-radio.js","sourceRoot":"","sources":["../../../../../src/components/molecules/inputs/mg-input-radio/mg-input-radio.tsx"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sEAAsE;AACtE,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAgB,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC;AAOhJ,MAAM,OAAO,YAAY;;IACvB;;kBAEc;IAEd,gBAAgB;IACR,WAAM,GAAuB,EAAE,CAAC;IAKxC,8CAA8C;IACtC,sBAAiB,GAAG,KAAK,CAAC;IA4JlC;;;OAGG;IACK,gBAAW,GAAG,CAAC,KAAgD,EAAE,EAAE;MACzE,IAAI,CAAC,aAAa,EAAE,CAAC;MACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;IACtD,CAAC,CAAC;IAEF;;OAEG;IACK,eAAU,GAAG,GAAS,EAAE;MAC9B,IAAI,CAAC,aAAa,EAAE,CAAC;MACrB,IAAI,CAAC,eAAe,EAAE,CAAC;IACzB,CAAC,CAAC;IAEF;;OAEG;IACK,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sourcesContent":["/* eslint-disable jsx-a11y/no-redundant-roles */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Component, Element, Event, h, Prop, EventEmitter, State, Watch, Method } from '@stencil/core';\nimport { MgInput } from '../MgInput';\nimport { ClassList, allItemsAreString } from '../../../../utils/components.utils';\nimport { initLocales } from '../../../../locales';\nimport { RadioOption } from './mg-input-radio.conf';\n\n/**\n * type Option validation function\n * @param option - radio option\n * @returns radio option type is valid\n */\nconst isOption = (option: RadioOption): boolean => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;\n\n@Component({\n tag: 'mg-input-radio',\n styleUrl: 'mg-input-radio.scss',\n shadow: true,\n})\nexport class MgInputRadio {\n /************\n * Internal *\n ************/\n\n // HTML selector\n private inputs: HTMLInputElement[] = [];\n\n // Locales\n private messages;\n\n // hasDisplayedError (triggered by blur event)\n private hasDisplayedError = false;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgInputRadioElement;\n\n /**\n * Component value\n */\n @Prop({ mutable: true }) value: any;\n @Watch('value')\n handleValue(newValue: any): void {\n this.valueChange.emit(newValue);\n }\n\n /**\n * Items are the possible options to select\n */\n @Prop() items!: string[] | RadioOption[];\n @Watch('items')\n validateItems(newValue: string[] | RadioOption[]): void {\n // Validate if items have required min length\n if (typeof newValue === 'object' && newValue.length < 2) {\n throw new Error('<mg-input-radio> prop \"items\" require at least 2 items.');\n }\n // String array\n else if (allItemsAreString(newValue as string[])) {\n this.options = newValue.map(item => ({ title: item, value: item, disabled: this.disabled }));\n }\n // Object array\n else if (newValue && (newValue as RadioOption[]).every(item => isOption(item))) {\n this.options = newValue as RadioOption[];\n } else {\n throw new Error('<mg-input-radio> prop \"items\" is required and all items must be the same type, string or RadioOption.');\n }\n }\n\n /**\n * Identifier is used for the element ID (id is a reserved prop in Stencil.js)\n */\n @Prop() identifier!: string;\n\n /**\n * Input name\n * If not set the value equals the identifier\n */\n @Prop() name: string = this.identifier;\n\n /**\n * Input label\n */\n @Prop() label!: string;\n\n /**\n * Define if label is displayed on top\n */\n @Prop() labelOnTop = false;\n\n /**\n * Define if label is visible\n */\n @Prop() labelHide = false;\n\n /**\n * Define if inputs are display verticaly\n */\n @Prop() inputVerticalList = false;\n\n /**\n * Define if input is required\n */\n @Prop() required = false;\n\n /**\n * Define if input is readonly\n */\n @Prop() readonly = false;\n\n /**\n * Define if input is disabled\n */\n @Prop() disabled = false;\n @Watch('required')\n @Watch('readonly')\n @Watch('disabled')\n handleValidityChange(newValue: boolean, _oldValue: boolean, prop: string): void {\n this.inputs.forEach(input => {\n input[prop] = newValue;\n });\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n this.hasDisplayedError = false;\n }\n }\n\n /**\n * Add a tooltip message next to the input\n */\n @Prop() tooltip: string;\n\n /**\n * Add a help text under the input, usually expected data format and example\n */\n @Prop() helpText: string;\n\n /**\n * Define input valid state\n */\n @Prop({ mutable: true }) valid: boolean;\n\n /**\n * Define input invalid state\n */\n @Prop({ mutable: true }) invalid: boolean;\n\n /**\n * Component classes\n */\n @State() classCollection: ClassList = new ClassList(['mg-input--radio']);\n\n /**\n * Error message to display\n */\n @State() errorMessage: string;\n\n /**\n * Formated items for display\n */\n @State() options: RadioOption[];\n\n /**\n * Emitted event when value change\n */\n @Event({ eventName: 'value-change' }) valueChange: EventEmitter<any>;\n\n /**\n * Emited event when checking validity\n */\n @Event({ eventName: 'input-valid' }) inputValid: EventEmitter<boolean>;\n\n /**\n * Public method to display errors\n */\n @Method()\n async displayError(): Promise<void> {\n this.checkValidity();\n this.setErrorMessage();\n this.hasDisplayedError = this.invalid;\n }\n\n /**\n * Handle input event\n * @param event - input event\n */\n private handleInput = (event: InputEvent & { target: HTMLInputElement }) => {\n this.checkValidity();\n this.value = this.options[event.target.value].value;\n };\n\n /**\n * Handle blur event\n */\n private handleBlur = (): void => {\n this.checkValidity();\n this.setErrorMessage();\n };\n\n /**\n * Check if input is valid\n */\n private checkValidity = (): void => {\n this.valid = this.readonly || this.disabled || this.getInvalidElement() === undefined;\n this.invalid = !this.valid;\n // We need to send valid event even if it is the same value\n this.inputValid.emit(this.valid);\n };\n\n /**\n * Set input error message\n */\n private setErrorMessage = (): void => {\n const invalidElement = this.getInvalidElement();\n\n // Set error message\n this.errorMessage = undefined;\n if (!this.valid && invalidElement.validity.valueMissing) {\n this.errorMessage = this.messages.errors.required;\n }\n };\n\n /**\n * get invalid element\n * @returns element\n */\n private getInvalidElement = (): HTMLInputElement => this.inputs.find((input: HTMLInputElement) => !input.disabled && !input.readOnly && !input.checkValidity());\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if component props are well configured on init\n * @returns timeout\n */\n componentWillLoad(): ReturnType<typeof setTimeout> {\n // Get locales\n this.messages = initLocales(this.element).messages;\n // Validate\n this.validateItems(this.items);\n // Check validity when component is ready\n // return a promise to process action only in the FIRST render().\n // https://stenciljs.com/docs/component-lifecycle#componentwillload\n return setTimeout(() => {\n this.checkValidity();\n }, 0);\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <MgInput\n identifier={this.identifier}\n classCollection={this.classCollection}\n ariaDescribedbyIDs={[]}\n label={this.label}\n labelOnTop={this.labelOnTop}\n labelHide={this.labelHide}\n required={this.required}\n disabled={this.disabled}\n readonly={this.readonly}\n mgWidth={undefined}\n value={this.value as string}\n readonlyValue={this.value as string}\n tooltip={this.tooltip}\n helpText={this.helpText}\n errorMessage={this.errorMessage}\n isFieldset={true}\n >\n <ul class={{ 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList }} role=\"list\">\n {this.options.map((input, index) => (\n <li key={input.title} class={{ 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled }}>\n <input\n type=\"radio\"\n id={this.identifier + '_' + index}\n name={this.identifier}\n value={index}\n checked={JSON.stringify(this.value) === JSON.stringify(this.options[index].value)}\n disabled={this.disabled || input.disabled}\n required={this.required}\n onBlur={this.handleBlur}\n onInput={this.handleInput}\n ref={(el: HTMLInputElement) => {\n if (el !== null) this.inputs[index] = el;\n }}\n />\n <label htmlFor={this.identifier + '_' + index}>{input.title}</label>\n </li>\n ))}\n </ul>\n </MgInput>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"mg-input-radio.js","sourceRoot":"","sources":["../../../../../src/components/molecules/inputs/mg-input-radio/mg-input-radio.tsx"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,sEAAsE;AACtE,uDAAuD;AACvD,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAgB,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvG,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD;;;;GAIG;AACH,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC;AAOhJ,MAAM,OAAO,YAAY;;IACvB;;kBAEc;IAEd,gBAAgB;IACR,WAAM,GAAuB,EAAE,CAAC;IAKxC,8CAA8C;IACtC,sBAAiB,GAAG,KAAK,CAAC;IA4LlC;;;OAGG;IACK,gBAAW,GAAG,CAAC,KAAgD,EAAE,EAAE;MACzE,IAAI,CAAC,aAAa,EAAE,CAAC;MACrB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC;IACtD,CAAC,CAAC;IAEF;;OAEG;IACK,eAAU,GAAG,GAAS,EAAE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C,QAAQ,IAAI,KAAK,CAAC,QAAQ,EACzC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,MAAM,EAAE,IAAI,CAAC,UAAU,EACvB,OAAO,EAAE,IAAI,CAAC,WAAW,EACzB,GAAG,EAAE,CAAC,EAAoB,EAAE,EAAE;YAC5B,IAAI,EAAE,KAAK,IAAI;cAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;UAC3C,CAAC,GACD;QACF,aAAO,OAAO,EAAE,IAAI,CAAC,UAAU,GAAG,GAAG,GAAG,KAAK,IAAG,KAAK,CAAC,KAAK,CAAS,CACjE,CACN,CAAC,CACC,CACG,CACX,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["/* eslint-disable jsx-a11y/no-redundant-roles */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { Component, Element, Event, h, Prop, EventEmitter, State, Watch, Method } from '@stencil/core';\nimport { MgInput } from '../MgInput';\nimport { ClassList, allItemsAreString } from '../../../../utils/components.utils';\nimport { initLocales } from '../../../../locales';\nimport { RadioOption } from './mg-input-radio.conf';\n\n/**\n * type Option validation function\n * @param option - radio option\n * @returns radio option type is valid\n */\nconst isOption = (option: RadioOption): boolean => typeof option === 'object' && typeof option.title === 'string' && option.value !== undefined;\n\n@Component({\n tag: 'mg-input-radio',\n styleUrl: 'mg-input-radio.scss',\n shadow: true,\n})\nexport class MgInputRadio {\n /************\n * Internal *\n ************/\n\n // HTML selector\n private inputs: HTMLInputElement[] = [];\n\n // Locales\n private messages;\n\n // hasDisplayedError (triggered by blur event)\n private hasDisplayedError = false;\n\n /**************\n * Decorators *\n **************/\n\n /**\n * Get component DOM element\n */\n @Element() element: HTMLMgInputRadioElement;\n\n /**\n * Component value\n */\n @Prop({ mutable: true }) value: any;\n @Watch('value')\n handleValue(newValue: any): void {\n this.valueChange.emit(newValue);\n }\n\n /**\n * Items are the possible options to select\n */\n @Prop() items!: string[] | RadioOption[];\n @Watch('items')\n validateItems(newValue: string[] | RadioOption[]): void {\n // Validate if items have required min length\n if (typeof newValue === 'object' && newValue.length < 2) {\n throw new Error('<mg-input-radio> prop \"items\" require at least 2 items.');\n }\n // String array\n else if (allItemsAreString(newValue as string[])) {\n this.options = newValue.map(item => ({ title: item, value: item, disabled: this.disabled }));\n }\n // Object array\n else if (newValue && (newValue as RadioOption[]).every(item => isOption(item))) {\n this.options = newValue as RadioOption[];\n } else {\n throw new Error('<mg-input-radio> prop \"items\" is required and all items must be the same type, string or RadioOption.');\n }\n }\n\n /**\n * Identifier is used for the element ID (id is a reserved prop in Stencil.js)\n */\n @Prop() identifier!: string;\n\n /**\n * Input name\n * If not set the value equals the identifier\n */\n @Prop() name: string = this.identifier;\n\n /**\n * Input label\n */\n @Prop() label!: string;\n\n /**\n * Define if label is displayed on top\n */\n @Prop() labelOnTop = false;\n\n /**\n * Define if label is visible\n */\n @Prop() labelHide = false;\n\n /**\n * Define if inputs are display verticaly\n */\n @Prop() inputVerticalList = false;\n\n /**\n * Define if input is required\n */\n @Prop() required = false;\n\n /**\n * Define if input is readonly\n */\n @Prop() readonly = false;\n\n /**\n * Define if input is disabled\n */\n @Prop() disabled = false;\n @Watch('required')\n @Watch('readonly')\n @Watch('disabled')\n handleValidityChange(newValue: boolean, _oldValue: boolean, prop: string): void {\n this.inputs.forEach(input => {\n input[prop] = newValue;\n });\n this.checkValidity();\n if (this.hasDisplayedError) {\n this.setErrorMessage();\n this.hasDisplayedError = false;\n }\n }\n\n /**\n * Add a tooltip message next to the input\n */\n @Prop() tooltip: string;\n\n /**\n * Add a help text under the input, usually expected data format and example\n */\n @Prop() helpText: string;\n\n /**\n * Define input valid state\n */\n @Prop({ mutable: true }) valid: boolean;\n\n /**\n * Define input invalid state\n */\n @Prop({ mutable: true }) invalid: boolean;\n\n /**\n * Component classes\n */\n @State() classCollection: ClassList = new ClassList(['mg-input--radio']);\n\n /**\n * Error message to display\n */\n @State() errorMessage: string;\n\n /**\n * Formated items for display\n */\n @State() options: RadioOption[];\n\n /**\n * Emitted event when value change\n */\n @Event({ eventName: 'value-change' }) valueChange: EventEmitter<any>;\n\n /**\n * Emited event when checking validity\n */\n @Event({ eventName: 'input-valid' }) inputValid: EventEmitter<boolean>;\n\n /**\n * Display input error if it exists.\n */\n @Method()\n async displayError(): Promise<void> {\n this.checkValidity();\n this.setErrorMessage();\n this.hasDisplayedError = this.invalid;\n }\n\n /**\n * Set an error and display a custom error message.\n * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.\n * It must be paired with an error message to display for the given context.\n * When used to set validity to `false`, you should use this method again to reset the validity to `true`.\n * @param valid - value indicating the validity\n * @param errorMessage - the error message to display\n */\n @Method()\n async setError(valid: MgInputRadio['valid'], errorMessage: string): Promise<void> {\n if (typeof valid !== 'boolean') {\n throw new Error('<mg-input-radio> method \"setError()\" param \"valid\" must be a boolean');\n } else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {\n throw new Error('<mg-input-radio> method \"setError()\" param \"errorMessage\" must be a string');\n } else {\n this.setValidity(valid);\n this.setErrorMessage(valid ? undefined : errorMessage);\n this.hasDisplayedError = this.invalid;\n }\n }\n\n /**\n * Method to set validity values\n * @param newValue - valid new value\n */\n private setValidity(newValue: MgInputRadio['valid']) {\n this.valid = newValue;\n this.invalid = !this.valid;\n // We need to send valid event even if it is the same value\n this.inputValid.emit(this.valid);\n }\n\n /**\n * Handle input event\n * @param event - input event\n */\n private handleInput = (event: InputEvent & { target: HTMLInputElement }) => {\n this.checkValidity();\n this.value = this.options[event.target.value].value;\n };\n\n /**\n * Handle blur event\n */\n private handleBlur = (): void => {\n this.checkValidity();\n this.setErrorMessage();\n };\n\n /**\n * Check if input is valid\n */\n private checkValidity = (): void => {\n this.setValidity(this.readonly || this.disabled || this.getInvalidElement() === undefined);\n };\n\n /**\n * Set input error message\n * @param errorMessage - errorMessage override\n */\n private setErrorMessage = (errorMessage?: string): void => {\n const invalidElement = this.getInvalidElement();\n\n // Set error message\n this.errorMessage = undefined;\n if (!this.valid) {\n if (errorMessage !== undefined) {\n this.errorMessage = errorMessage;\n } else if (invalidElement.validity.valueMissing) {\n this.errorMessage = this.messages.errors.required;\n }\n }\n };\n\n /**\n * get invalid element\n * @returns element\n */\n private getInvalidElement = (): HTMLInputElement => this.inputs.find((input: HTMLInputElement) => !input.disabled && !input.readOnly && !input.checkValidity());\n\n /*************\n * Lifecycle *\n *************/\n\n /**\n * Check if component props are well configured on init\n * @returns timeout\n */\n componentWillLoad(): ReturnType<typeof setTimeout> {\n // Get locales\n this.messages = initLocales(this.element).messages;\n // Validate\n this.validateItems(this.items);\n // Check validity when component is ready\n // return a promise to process action only in the FIRST render().\n // https://stenciljs.com/docs/component-lifecycle#componentwillload\n return setTimeout(() => {\n this.checkValidity();\n }, 0);\n }\n\n /**\n * Render\n * @returns HTML Element\n */\n render(): HTMLElement {\n return (\n <MgInput\n identifier={this.identifier}\n classCollection={this.classCollection}\n ariaDescribedbyIDs={[]}\n label={this.label}\n labelOnTop={this.labelOnTop}\n labelHide={this.labelHide}\n required={this.required}\n disabled={this.disabled}\n readonly={this.readonly}\n mgWidth={undefined}\n value={this.value as string}\n readonlyValue={this.value as string}\n tooltip={this.tooltip}\n helpText={this.helpText}\n errorMessage={this.errorMessage}\n isFieldset={true}\n >\n <ul class={{ 'mg-input__input-group-container': true, 'mg-input__input-group-container--vertical': this.inputVerticalList }} role=\"list\">\n {this.options.map((input, index) => (\n <li key={input.title} class={{ 'mg-input__input-group': true, 'mg-input__input-group--disabled': this.disabled || input.disabled }}>\n <input\n type=\"radio\"\n id={this.identifier + '_' + index}\n name={this.identifier}\n value={index}\n checked={JSON.stringify(this.value) === JSON.stringify(this.options[index].value)}\n disabled={this.disabled || input.disabled}\n required={this.required}\n onBlur={this.handleBlur}\n onInput={this.handleInput}\n ref={(el: HTMLInputElement) => {\n if (el !== null) this.inputs[index] = el;\n }}\n />\n <label htmlFor={this.identifier + '_' + index}>{input.title}</label>\n </li>\n ))}\n </ul>\n </MgInput>\n );\n }\n}\n"]}
@@ -227,6 +227,66 @@ describe('mg-input-radio', () => {
227
227
  await page.waitForChanges();
228
228
  expect(page.root).toMatchSnapshot();
229
229
  });
230
+ test.each([
231
+ {
232
+ valid: true,
233
+ errorMessage: 'Override error',
234
+ },
235
+ {
236
+ valid: false,
237
+ errorMessage: 'Override error',
238
+ },
239
+ ])("should display override error with setError component's public method", async (params) => {
240
+ const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true });
241
+ expect(page.root).toMatchSnapshot();
242
+ const element = page.doc.querySelector('mg-input-radio');
243
+ const allInputs = element.shadowRoot.querySelectorAll('input');
244
+ //mock validity
245
+ allInputs.forEach(input => {
246
+ input.checkValidity = jest.fn(() => false);
247
+ Object.defineProperty(input, 'validity', {
248
+ get: jest.fn(() => ({
249
+ valueMissing: true,
250
+ })),
251
+ });
252
+ });
253
+ await element.setError(params.valid, params.errorMessage);
254
+ await page.waitForChanges();
255
+ expect(page.root).toMatchSnapshot();
256
+ });
257
+ test.each([
258
+ {
259
+ valid: '',
260
+ errorMessage: 'Override error',
261
+ error: '<mg-input-radio> method "setError()" param "valid" must be a boolean',
262
+ },
263
+ {
264
+ valid: undefined,
265
+ errorMessage: 'Override error',
266
+ error: '<mg-input-radio> method "setError()" param "valid" must be a boolean',
267
+ },
268
+ {
269
+ valid: true,
270
+ errorMessage: ' ',
271
+ error: '<mg-input-radio> method "setError()" param "errorMessage" must be a string',
272
+ },
273
+ {
274
+ valid: true,
275
+ errorMessage: true,
276
+ error: '<mg-input-radio> method "setError()" param "errorMessage" must be a string',
277
+ },
278
+ ])("shloud throw error with setError component's public method invalid params", async (params) => {
279
+ expect.assertions(1);
280
+ try {
281
+ const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true });
282
+ const element = page.doc.querySelector('mg-input-radio');
283
+ await element.setError(params.valid, params.errorMessage);
284
+ await page.waitForChanges();
285
+ }
286
+ catch (err) {
287
+ expect(err.message).toMatch(params.error);
288
+ }
289
+ });
230
290
  test.each(['fr', 'xx'])('display error message with locale: %s', async (lang) => {
231
291
  const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'My help text', required: true, lang });
232
292
  const element = page.doc.querySelector('mg-input-radio');
@@ -1 +1 @@
1
- {"version":3,"file":"mg-input-radio.spec.js","sourceRoot":"","sources":["../../../../../../src/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,QAAQ,MAAM,yCAAyC,CAAC;AAE/D,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE;EACrB,MAAM,IAAI,GAAG,WAAW,CAAC;IACvB,UAAU,EAAE,CAAC,YAAY,CAAC;IAC1B,QAAQ,EAAE,GAAG,EAAE,CAAC,sCAAoB,IAAI,EAAmB;GAC5D,CAAC,CAAC;EAEH,IAAI,CAAC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AE,CAAC;IAE5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEzE,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;IACzB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAE5B,wEAAwE;IACxE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;IAEvD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IACxB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAE5B,yDAAyD;IACzD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;EACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { h } from '@stencil/core';\nimport { newSpecPage } from '@stencil/core/testing';\nimport { MgInputRadio } from '../mg-input-radio';\nimport { RadioOption } from '../mg-input-radio.conf';\nimport messages from '../../../../../locales/en/messages.json';\n\nconst getPage = args => {\n const page = newSpecPage({\n components: [MgInputRadio],\n template: () => <mg-input-radio {...args}></mg-input-radio>,\n });\n\n jest.runAllTimers();\n\n return page;\n};\n\ndescribe('mg-input-radio', () => {\n beforeEach(() => jest.useFakeTimers());\n afterEach(() => jest.runOnlyPendingTimers());\n test.each([\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'] },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: 'u' },\n { title: 'robin', value: 'i' },\n { title: 'joker', value: 'o' },\n { title: 'bane', value: 'a' },\n ],\n },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: 1 },\n { title: 'robin', value: 2 },\n { title: 'joker', value: 3 },\n { title: 'bane', value: 4 },\n ],\n },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: true },\n { title: 'robin', value: false },\n { title: 'joker', value: false },\n { title: 'bane', value: false },\n ],\n },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], labelOnTop: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], labelHide: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], inputVerticalList: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, readonly: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, disabled: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], readonly: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], readonly: true, labelOnTop: true, tooltip: 'Tooltip message' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], disabled: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'Hello joker' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], tooltip: 'My Tooltip Message' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], tooltip: 'My Tooltip Message', labelOnTop: true },\n ])('Should render with args %s:', async args => {\n const { root } = await getPage(args);\n expect(root).toMatchSnapshot();\n });\n\n test.each(['', ' ', undefined])('Should not render with invalid identifier property: %s', async identifier => {\n expect.assertions(1);\n try {\n await getPage({ identifier, items: ['batman', 'robin', 'joker', 'bane'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"identifier\" is required.');\n }\n });\n\n test.each(['', ' ', undefined])('Should throw error with invalid label property: %s', async label => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label, items: ['batman', 'robin', 'joker', 'bane'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"label\" is required.');\n }\n });\n\n test('Should throw an error with labelOnTop & labelHide set to true', async () => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label: 'batman', labelOnTop: true, labelHide: true, items: ['batman', 'joker'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"labelOnTop\" must not be paired with the prop \"labelHide\"');\n }\n });\n\n test.each([[['batman']], [[{ title: 'batman', value: 'u' }]]])('Should throw an error with less than 2 items, case %s', async items => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label: 'batman', labelOnTop: true, labelHide: true, items });\n } catch (err) {\n expect(err.message).toMatch('<mg-input-radio> prop \"items\" require at least 2 items.');\n }\n });\n\n test.each([\n [['batman', { title: 'batman', value: 'batman' }]],\n [['batman', { batman: 'batman' }]],\n [[true, false]],\n [[1, 2, 3]],\n [[true, 1, 'batman']],\n [[{ title: 'batman', value: 'batman' }, { batman: 'batman' }]],\n [\n [\n { title: 'batman', value: undefined },\n { title: 'batman', value: 'test' },\n ],\n ],\n ])('Should throw error with invalid items property: %s', async items => {\n expect.assertions(1);\n try {\n await getPage({ label: 'Label', items });\n } catch (err) {\n expect(err.message).toMatch('<mg-input-radio> prop \"items\" is required and all items must be the same type, string or RadioOption.');\n }\n });\n\n test.each([\n { items: ['batman', 'robin', 'joker', 'bane'], selectedIndex: 3 },\n {\n items: [\n { title: 'batman', value: 'u' },\n { title: 'robin', value: 'i' },\n { title: 'joker', value: 'o' },\n { title: 'bane', value: 'a' },\n ],\n selectedIndex: 2,\n },\n {\n items: [\n { title: 'batman', value: 1 },\n { title: 'robin', value: 2 },\n { title: 'joker', value: 3 },\n { title: 'bane', value: 4 },\n ],\n selectedIndex: 1,\n },\n {\n items: [\n { title: 'batman', value: true },\n { title: 'robin', value: false },\n ],\n selectedIndex: 0,\n },\n {\n items: [\n { title: 'batman', value: { name: 'Batman' } },\n { title: 'robin', value: { name: 'Robin' } },\n ],\n selectedIndex: 1,\n },\n ])('Should trigger events for items (%s) with selectedIndex (%s)', async ({ items, selectedIndex }) => {\n const args = { label: 'label', items, identifier: 'identifier', helpText: 'My help text' };\n const page = await getPage(args);\n\n const element = page.doc.querySelector('mg-input-radio');\n const input = element.shadowRoot.querySelector('input');\n\n //mock validity\n input.checkValidity = jest.fn(() => true);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: false,\n })),\n });\n\n jest.spyOn(page.rootInstance.valueChange, 'emit');\n\n input.dispatchEvent(new CustomEvent('focus', { bubbles: true }));\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot(); //Snapshot on focus\n\n input.value = selectedIndex.toString();\n input.dispatchEvent(new CustomEvent('input', { bubbles: true }));\n await page.waitForChanges();\n const expectedEmitValue = typeof items[selectedIndex] === 'object' ? (items[selectedIndex] as RadioOption).value : items[selectedIndex];\n expect(page.rootInstance.valueChange.emit).toHaveBeenCalledWith(expectedEmitValue);\n });\n\n describe.each(['readonly', 'disabled'])('validity, case next state is %s', nextState => {\n test.each([\n { validity: true, valueMissing: false },\n { validity: false, valueMissing: true },\n ])('validity (%s), valueMissing (%s)', async ({ validity, valueMissing }) => {\n const args = { label: 'label', items: ['batman', 'robin', 'joker', 'bane'], identifier: 'identifier', patternErrorMessage: 'Non' };\n const page = await getPage(args);\n\n const element = page.doc.querySelector('mg-input-radio');\n const input = element.shadowRoot.querySelector('input');\n\n //mock validity\n input.checkValidity = jest.fn(() => validity);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing,\n })),\n });\n\n input.dispatchEvent(new CustomEvent('blur', { bubbles: true }));\n await page.waitForChanges();\n\n if (validity) {\n expect(page.rootInstance.errorMessage).toBeUndefined();\n } else if (valueMissing) {\n expect(page.rootInstance.errorMessage).toEqual(messages.errors.required);\n }\n expect(page.rootInstance.valid).toEqual(validity);\n expect(page.rootInstance.invalid).toEqual(!validity);\n if (valueMissing) {\n expect(page.root).toMatchSnapshot(); //Snapshot with readonly/disabled FALSE\n element[nextState] = true;\n await page.waitForChanges();\n expect(page.root).toMatchSnapshot(); //Snapshot with readonly/disabled TRUE\n }\n });\n });\n\n test(\"display error with displayError component's public method\", async () => {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'My help text', required: true });\n\n expect(page.root).toMatchSnapshot();\n\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs.forEach(input => {\n input.checkValidity = jest.fn(() => false);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: true,\n })),\n });\n });\n\n await element.displayError();\n\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot();\n });\n\n test.each(['fr', 'xx'])('display error message with locale: %s', async lang => {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'My help text', required: true, lang });\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs.forEach(input => {\n input.checkValidity = jest.fn(() => false);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: true,\n })),\n });\n });\n\n await element.displayError();\n\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot();\n });\n\n test('Should remove error on input when required change dynamically', async () => {\n const page = await getPage({\n label: 'label',\n identifier: 'identifier',\n items: ['batman', 'robin'],\n required: true,\n });\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs[0].checkValidity = jest\n .fn()\n .mockReturnValueOnce(false) //1\n .mockReturnValueOnce(false) //1\n .mockReturnValueOnce(true) //2\n .mockReturnValueOnce(true) //2\n .mockReturnValueOnce(false) //3\n .mockReturnValueOnce(false); //3\n allInputs[1].checkValidity = jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(true); //2\n Object.defineProperty(allInputs[0], 'validity', {\n get: jest\n .fn()\n .mockReturnValueOnce({\n valueMissing: true, //1\n })\n .mockReturnValueOnce({\n valueMissing: false, //2\n })\n .mockReturnValueOnce({\n valueMissing: true, //3\n }),\n });\n\n await element.displayError();\n await page.waitForChanges();\n\n expect(page.rootInstance.hasDisplayedError).toEqual(true);\n expect(page.rootInstance.errorMessage).toEqual(messages.errors.required);\n\n element.required = false;\n await page.waitForChanges();\n\n // Error message should disapear and change the hasDisplayedError status\n expect(page.rootInstance.hasDisplayedError).toEqual(false);\n expect(page.rootInstance.errorMessage).toBeUndefined();\n\n element.required = true;\n await page.waitForChanges();\n\n // If back on required the message is still not displayed\n expect(page.rootInstance.hasDisplayedError).toEqual(false);\n expect(page.rootInstance.errorMessage).toBeUndefined();\n });\n});\n"]}
1
+ {"version":3,"file":"mg-input-radio.spec.js","sourceRoot":"","sources":["../../../../../../src/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,QAAQ,MAAM,yCAAyC,CAAC;AAE/D,MAAM,OAAO,GAAG,IAAI,CAAC,EAAE;EACrB,MAAM,IAAI,GAAG,WAAW,CAAC;IACvB,UAAU,EAAE,CAAC,YAAY,CAAC;IAC1B,QAAQ,EAAE,GAAG,EAAE,CAAC,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AC1D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEzE,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;IACzB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAE5B,wEAAwE;IACxE,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;IAEvD,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IACxB,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC;IAE5B,yDAAyD;IACzD,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,aAAa,EAAE,CAAC;EACzD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { h } from '@stencil/core';\nimport { newSpecPage } from '@stencil/core/testing';\nimport { MgInputRadio } from '../mg-input-radio';\nimport { RadioOption } from '../mg-input-radio.conf';\nimport messages from '../../../../../locales/en/messages.json';\n\nconst getPage = args => {\n const page = newSpecPage({\n components: [MgInputRadio],\n template: () => <mg-input-radio {...args}></mg-input-radio>,\n });\n\n jest.runAllTimers();\n\n return page;\n};\n\ndescribe('mg-input-radio', () => {\n beforeEach(() => jest.useFakeTimers());\n afterEach(() => jest.runOnlyPendingTimers());\n test.each([\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'] },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: 'u' },\n { title: 'robin', value: 'i' },\n { title: 'joker', value: 'o' },\n { title: 'bane', value: 'a' },\n ],\n },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: 1 },\n { title: 'robin', value: 2 },\n { title: 'joker', value: 3 },\n { title: 'bane', value: 4 },\n ],\n },\n {\n label: 'label',\n identifier: 'identifier',\n items: [\n { title: 'batman', value: true },\n { title: 'robin', value: false },\n { title: 'joker', value: false },\n { title: 'bane', value: false },\n ],\n },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], labelOnTop: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], labelHide: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], inputVerticalList: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, readonly: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true, disabled: true, helpText: 'My help text', value: 'batman' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], readonly: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], readonly: true, labelOnTop: true, tooltip: 'Tooltip message' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], disabled: true },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'Hello joker' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], tooltip: 'My Tooltip Message' },\n { label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], tooltip: 'My Tooltip Message', labelOnTop: true },\n ])('Should render with args %s:', async args => {\n const { root } = await getPage(args);\n expect(root).toMatchSnapshot();\n });\n\n test.each(['', ' ', undefined])('Should not render with invalid identifier property: %s', async identifier => {\n expect.assertions(1);\n try {\n await getPage({ identifier, items: ['batman', 'robin', 'joker', 'bane'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"identifier\" is required.');\n }\n });\n\n test.each(['', ' ', undefined])('Should throw error with invalid label property: %s', async label => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label, items: ['batman', 'robin', 'joker', 'bane'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"label\" is required.');\n }\n });\n\n test('Should throw an error with labelOnTop & labelHide set to true', async () => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label: 'batman', labelOnTop: true, labelHide: true, items: ['batman', 'joker'] });\n } catch (err) {\n expect(err.message).toMatch('<mg-input> prop \"labelOnTop\" must not be paired with the prop \"labelHide\"');\n }\n });\n\n test.each([[['batman']], [[{ title: 'batman', value: 'u' }]]])('Should throw an error with less than 2 items, case %s', async items => {\n expect.assertions(1);\n try {\n await getPage({ identifier: 'identifier', label: 'batman', labelOnTop: true, labelHide: true, items });\n } catch (err) {\n expect(err.message).toMatch('<mg-input-radio> prop \"items\" require at least 2 items.');\n }\n });\n\n test.each([\n [['batman', { title: 'batman', value: 'batman' }]],\n [['batman', { batman: 'batman' }]],\n [[true, false]],\n [[1, 2, 3]],\n [[true, 1, 'batman']],\n [[{ title: 'batman', value: 'batman' }, { batman: 'batman' }]],\n [\n [\n { title: 'batman', value: undefined },\n { title: 'batman', value: 'test' },\n ],\n ],\n ])('Should throw error with invalid items property: %s', async items => {\n expect.assertions(1);\n try {\n await getPage({ label: 'Label', items });\n } catch (err) {\n expect(err.message).toMatch('<mg-input-radio> prop \"items\" is required and all items must be the same type, string or RadioOption.');\n }\n });\n\n test.each([\n { items: ['batman', 'robin', 'joker', 'bane'], selectedIndex: 3 },\n {\n items: [\n { title: 'batman', value: 'u' },\n { title: 'robin', value: 'i' },\n { title: 'joker', value: 'o' },\n { title: 'bane', value: 'a' },\n ],\n selectedIndex: 2,\n },\n {\n items: [\n { title: 'batman', value: 1 },\n { title: 'robin', value: 2 },\n { title: 'joker', value: 3 },\n { title: 'bane', value: 4 },\n ],\n selectedIndex: 1,\n },\n {\n items: [\n { title: 'batman', value: true },\n { title: 'robin', value: false },\n ],\n selectedIndex: 0,\n },\n {\n items: [\n { title: 'batman', value: { name: 'Batman' } },\n { title: 'robin', value: { name: 'Robin' } },\n ],\n selectedIndex: 1,\n },\n ])('Should trigger events for items (%s) with selectedIndex (%s)', async ({ items, selectedIndex }) => {\n const args = { label: 'label', items, identifier: 'identifier', helpText: 'My help text' };\n const page = await getPage(args);\n\n const element = page.doc.querySelector('mg-input-radio');\n const input = element.shadowRoot.querySelector('input');\n\n //mock validity\n input.checkValidity = jest.fn(() => true);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: false,\n })),\n });\n\n jest.spyOn(page.rootInstance.valueChange, 'emit');\n\n input.dispatchEvent(new CustomEvent('focus', { bubbles: true }));\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot(); //Snapshot on focus\n\n input.value = selectedIndex.toString();\n input.dispatchEvent(new CustomEvent('input', { bubbles: true }));\n await page.waitForChanges();\n const expectedEmitValue = typeof items[selectedIndex] === 'object' ? (items[selectedIndex] as RadioOption).value : items[selectedIndex];\n expect(page.rootInstance.valueChange.emit).toHaveBeenCalledWith(expectedEmitValue);\n });\n\n describe.each(['readonly', 'disabled'])('validity, case next state is %s', nextState => {\n test.each([\n { validity: true, valueMissing: false },\n { validity: false, valueMissing: true },\n ])('validity (%s), valueMissing (%s)', async ({ validity, valueMissing }) => {\n const args = { label: 'label', items: ['batman', 'robin', 'joker', 'bane'], identifier: 'identifier', patternErrorMessage: 'Non' };\n const page = await getPage(args);\n\n const element = page.doc.querySelector('mg-input-radio');\n const input = element.shadowRoot.querySelector('input');\n\n //mock validity\n input.checkValidity = jest.fn(() => validity);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing,\n })),\n });\n\n input.dispatchEvent(new CustomEvent('blur', { bubbles: true }));\n await page.waitForChanges();\n\n if (validity) {\n expect(page.rootInstance.errorMessage).toBeUndefined();\n } else if (valueMissing) {\n expect(page.rootInstance.errorMessage).toEqual(messages.errors.required);\n }\n expect(page.rootInstance.valid).toEqual(validity);\n expect(page.rootInstance.invalid).toEqual(!validity);\n if (valueMissing) {\n expect(page.root).toMatchSnapshot(); //Snapshot with readonly/disabled FALSE\n element[nextState] = true;\n await page.waitForChanges();\n expect(page.root).toMatchSnapshot(); //Snapshot with readonly/disabled TRUE\n }\n });\n });\n\n test(\"display error with displayError component's public method\", async () => {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'My help text', required: true });\n\n expect(page.root).toMatchSnapshot();\n\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs.forEach(input => {\n input.checkValidity = jest.fn(() => false);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: true,\n })),\n });\n });\n\n await element.displayError();\n\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot();\n });\n\n test.each([\n {\n valid: true,\n errorMessage: 'Override error',\n },\n {\n valid: false,\n errorMessage: 'Override error',\n },\n ])(\"should display override error with setError component's public method\", async params => {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true });\n\n expect(page.root).toMatchSnapshot();\n\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs.forEach(input => {\n input.checkValidity = jest.fn(() => false);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: true,\n })),\n });\n });\n\n await element.setError(params.valid, params.errorMessage);\n\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot();\n });\n\n test.each([\n {\n valid: '',\n errorMessage: 'Override error',\n error: '<mg-input-radio> method \"setError()\" param \"valid\" must be a boolean',\n },\n {\n valid: undefined,\n errorMessage: 'Override error',\n error: '<mg-input-radio> method \"setError()\" param \"valid\" must be a boolean',\n },\n {\n valid: true,\n errorMessage: ' ',\n error: '<mg-input-radio> method \"setError()\" param \"errorMessage\" must be a string',\n },\n {\n valid: true,\n errorMessage: true,\n error: '<mg-input-radio> method \"setError()\" param \"errorMessage\" must be a string',\n },\n ])(\"shloud throw error with setError component's public method invalid params\", async params => {\n expect.assertions(1);\n try {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], required: true });\n const element = page.doc.querySelector('mg-input-radio');\n\n await element.setError(params.valid as unknown as boolean, params.errorMessage as unknown as string);\n await page.waitForChanges();\n } catch (err) {\n expect(err.message).toMatch(params.error);\n }\n });\n\n test.each(['fr', 'xx'])('display error message with locale: %s', async lang => {\n const page = await getPage({ label: 'label', identifier: 'identifier', items: ['batman', 'robin', 'joker', 'bane'], helpText: 'My help text', required: true, lang });\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs.forEach(input => {\n input.checkValidity = jest.fn(() => false);\n Object.defineProperty(input, 'validity', {\n get: jest.fn(() => ({\n valueMissing: true,\n })),\n });\n });\n\n await element.displayError();\n\n await page.waitForChanges();\n\n expect(page.root).toMatchSnapshot();\n });\n\n test('Should remove error on input when required change dynamically', async () => {\n const page = await getPage({\n label: 'label',\n identifier: 'identifier',\n items: ['batman', 'robin'],\n required: true,\n });\n const element = page.doc.querySelector('mg-input-radio');\n const allInputs = element.shadowRoot.querySelectorAll('input');\n\n //mock validity\n allInputs[0].checkValidity = jest\n .fn()\n .mockReturnValueOnce(false) //1\n .mockReturnValueOnce(false) //1\n .mockReturnValueOnce(true) //2\n .mockReturnValueOnce(true) //2\n .mockReturnValueOnce(false) //3\n .mockReturnValueOnce(false); //3\n allInputs[1].checkValidity = jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(true); //2\n Object.defineProperty(allInputs[0], 'validity', {\n get: jest\n .fn()\n .mockReturnValueOnce({\n valueMissing: true, //1\n })\n .mockReturnValueOnce({\n valueMissing: false, //2\n })\n .mockReturnValueOnce({\n valueMissing: true, //3\n }),\n });\n\n await element.displayError();\n await page.waitForChanges();\n\n expect(page.rootInstance.hasDisplayedError).toEqual(true);\n expect(page.rootInstance.errorMessage).toEqual(messages.errors.required);\n\n element.required = false;\n await page.waitForChanges();\n\n // Error message should disapear and change the hasDisplayedError status\n expect(page.rootInstance.hasDisplayedError).toEqual(false);\n expect(page.rootInstance.errorMessage).toBeUndefined();\n\n element.required = true;\n await page.waitForChanges();\n\n // If back on required the message is still not displayed\n expect(page.rootInstance.hasDisplayedError).toEqual(false);\n expect(page.rootInstance.errorMessage).toBeUndefined();\n });\n});\n"]}
@@ -107,19 +107,22 @@ export class MgInputSelect {
107
107
  */
108
108
  this.checkValidity = () => {
109
109
  var _a;
110
- this.valid = !this.isDisabledValue() && (this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
111
- this.invalid = !this.valid;
112
- // We need to send valid event even if it is the same value
113
- this.inputValid.emit(this.valid);
110
+ this.setValidity(!this.isDisabledValue() && (this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true)));
114
111
  };
115
112
  /**
116
113
  * Set input error message
114
+ * @param errorMessage - errorMessage override
117
115
  */
118
- this.setErrorMessage = () => {
116
+ this.setErrorMessage = (errorMessage) => {
119
117
  // Set error message
120
118
  this.errorMessage = undefined;
121
- if (!this.valid && this.input.validity.valueMissing) {
122
- this.errorMessage = this.messages.errors.required;
119
+ if (!this.valid) {
120
+ if (errorMessage !== undefined) {
121
+ this.errorMessage = errorMessage;
122
+ }
123
+ else if (this.input.validity.valueMissing) {
124
+ this.errorMessage = this.messages.errors.required;
125
+ }
123
126
  }
124
127
  };
125
128
  /**
@@ -203,13 +206,44 @@ export class MgInputSelect {
203
206
  }
204
207
  }
205
208
  /**
206
- * Public method to display errors
209
+ * Display input error if it exists.
207
210
  */
208
211
  async displayError() {
209
212
  this.checkValidity();
210
213
  this.setErrorMessage();
211
214
  this.hasDisplayedError = this.invalid;
212
215
  }
216
+ /**
217
+ * Set an error and display a custom error message.
218
+ * This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
219
+ * It must be paired with an error message to display for the given context.
220
+ * When used to set validity to `false`, you should use this method again to reset the validity to `true`.
221
+ * @param valid - value indicating the validity
222
+ * @param errorMessage - the error message to display
223
+ */
224
+ async setError(valid, errorMessage) {
225
+ if (typeof valid !== 'boolean') {
226
+ throw new Error('<mg-input-select> method "setError()" param "valid" must be a boolean');
227
+ }
228
+ else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
229
+ throw new Error('<mg-input-select> method "setError()" param "errorMessage" must be a string');
230
+ }
231
+ else {
232
+ this.setValidity(valid);
233
+ this.setErrorMessage(valid ? undefined : errorMessage);
234
+ this.hasDisplayedError = this.invalid;
235
+ }
236
+ }
237
+ /**
238
+ * Method to set validity values
239
+ * @param newValue - valid new value
240
+ */
241
+ setValidity(newValue) {
242
+ this.valid = newValue;
243
+ this.invalid = !this.valid;
244
+ // We need to send valid event even if it is the same value
245
+ this.inputValid.emit(this.valid);
246
+ }
213
247
  /*************
214
248
  * Lifecycle *
215
249
  *************/
@@ -646,9 +680,48 @@ export class MgInputSelect {
646
680
  "return": "Promise<void>"
647
681
  },
648
682
  "docs": {
649
- "text": "Public method to display errors",
683
+ "text": "Display input error if it exists.",
650
684
  "tags": []
651
685
  }
686
+ },
687
+ "setError": {
688
+ "complexType": {
689
+ "signature": "(valid: MgInputSelect['valid'], errorMessage: string) => Promise<void>",
690
+ "parameters": [{
691
+ "tags": [{
692
+ "name": "param",
693
+ "text": "valid - value indicating the validity"
694
+ }],
695
+ "text": "- value indicating the validity"
696
+ }, {
697
+ "tags": [{
698
+ "name": "param",
699
+ "text": "errorMessage - the error message to display"
700
+ }],
701
+ "text": "- the error message to display"
702
+ }],
703
+ "references": {
704
+ "Promise": {
705
+ "location": "global",
706
+ "id": "global::Promise"
707
+ },
708
+ "MgInputSelect": {
709
+ "location": "global",
710
+ "id": "global::MgInputSelect"
711
+ }
712
+ },
713
+ "return": "Promise<void>"
714
+ },
715
+ "docs": {
716
+ "text": "Set an error and display a custom error message.\nThis method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.\nIt must be paired with an error message to display for the given context.\nWhen used to set validity to `false`, you should use this method again to reset the validity to `true`.",
717
+ "tags": [{
718
+ "name": "param",
719
+ "text": "valid - value indicating the validity"
720
+ }, {
721
+ "name": "param",
722
+ "text": "errorMessage - the error message to display"
723
+ }]
724
+ }
652
725
  }
653
726
  };
654
727
  }