@madgex/design-system 5.9.0 → 5.10.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 (31) hide show
  1. package/dist/_tokens/css/_tokens.css +1 -1
  2. package/dist/_tokens/js/_tokens-module.js +1 -1
  3. package/dist/_tokens/scss/_tokens.scss +1 -1
  4. package/package.json +2 -2
  5. package/src/components/inputs/_message/_template.njk +5 -4
  6. package/src/components/inputs/checkbox-list/README.md +1 -0
  7. package/src/components/inputs/checkbox-list/_template.njk +16 -1
  8. package/src/components/inputs/combobox/README.md +1 -0
  9. package/src/components/inputs/combobox/_template.njk +33 -2
  10. package/src/components/inputs/combobox/combobox.config.js +15 -0
  11. package/src/components/inputs/combobox/combobox.njk +2 -0
  12. package/src/components/inputs/file-upload/README.md +2 -1
  13. package/src/components/inputs/file-upload/_template.njk +17 -0
  14. package/src/components/inputs/file-upload/file-upload.config.js +12 -0
  15. package/src/components/inputs/input/README.md +1 -0
  16. package/src/components/inputs/input/_template.njk +18 -1
  17. package/src/components/inputs/radio/README.md +1 -0
  18. package/src/components/inputs/radio/_template.njk +15 -1
  19. package/src/components/inputs/radio/radio.config.js +26 -0
  20. package/src/components/inputs/radio/radio.njk +3 -1
  21. package/src/components/inputs/select/README.md +1 -0
  22. package/src/components/inputs/select/_template.njk +18 -1
  23. package/src/components/inputs/select/select.config.js +24 -0
  24. package/src/components/inputs/single-checkbox/README.md +1 -0
  25. package/src/components/inputs/single-checkbox/_template.njk +16 -2
  26. package/src/components/inputs/single-checkbox/single-checkbox.config.js +15 -0
  27. package/src/components/inputs/single-checkbox/single-checkbox.njk +26 -14
  28. package/src/components/inputs/text-editor/README.md +1 -0
  29. package/src/components/inputs/text-editor/_template.njk +19 -1
  30. package/src/components/inputs/textarea/README.md +1 -0
  31. package/src/components/inputs/textarea/_template.njk +22 -1
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Tue, 14 Mar 2023 11:11:27 GMT
3
+ * Generated on Mon, 20 Mar 2023 08:22:48 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Tue, 14 Mar 2023 11:11:27 GMT
3
+ * Generated on Mon, 20 Mar 2023 08:22:48 GMT
4
4
  */
5
5
 
6
6
  module.exports = {
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  * Do not edit directly
4
- * Generated on Tue, 14 Mar 2023 11:11:27 GMT
4
+ * Generated on Mon, 20 Mar 2023 08:22:48 GMT
5
5
  */
6
6
 
7
7
  $mds-color-brand-1-light: #2990e0 !default;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@madgex/design-system",
3
3
  "author": "Madgex",
4
4
  "license": "UNLICENSED",
5
- "version": "5.9.0",
5
+ "version": "5.10.0",
6
6
  "main": "dist/js/index.js",
7
7
  "files": [
8
8
  "dist",
@@ -89,5 +89,5 @@
89
89
  "webpack-dev-server": "^3.11.2",
90
90
  "webpack-stream": "^6.1.2"
91
91
  },
92
- "gitHead": "ac3e96e389676e6e6dfbca5f6ed6e78f1289693e"
92
+ "gitHead": "a778c81350d63b335cc68caab575ba2c2176a398"
93
93
  }
@@ -1,9 +1,9 @@
1
1
  {% from "../../icons/_macro.njk" import MdsIcon %}
2
2
 
3
- {% if params.helpText %}
3
+ {% if params.helpText and params.helpTextId %}
4
4
  <div
5
5
  class="mds-form-message"
6
- id="{{ params.id }}-help-text">
6
+ id="{{ params.helpTextId }}">
7
7
  {{ params.helpText }}
8
8
  </div>
9
9
  {% endif %}
@@ -11,12 +11,13 @@
11
11
  <div
12
12
  aria-live="polite"
13
13
  class="mds-form-message mds-form-message--error"
14
- id="{{ params.id }}-validation-error">
14
+ id="{{ params.validationErrorId }}">
15
15
  {{- MdsIcon({
16
16
  iconName: 'cross',
17
17
  classes: 'mds-icon--sm',
18
18
  hasContainer: true,
19
- containerClasses: 'mds-icon-container--circle mds-icon-container--error mds-icon-container--before'
19
+ containerClasses: 'mds-icon-container--circle mds-icon-container--error mds-icon-container--before',
20
+ visuallyHiddenLabel: params.i18n.errorIcon | default('Error. ')
20
21
  })
21
22
  -}}
22
23
  {{- params.validationError -}}
@@ -17,6 +17,7 @@
17
17
  ```
18
18
  i18n: {
19
19
  requiredIcon: 'required', // visually hidden text for the required icon (label)
20
+ errorIcon: default is 'Error', // visually hidden text for the error icon
20
21
  accordionTrigger: 'Select options under {label}' // text to improve a11y on nested checkboxes - please note the use of `{label}` to get the name of the option
21
22
  }
22
23
  ```
@@ -3,12 +3,25 @@
3
3
  {% from "../../accordion/_macro.njk" import MdsAccordion %}
4
4
  {% from "../../icons/_macro.njk" import MdsIcon %}
5
5
  {% from "../_checkbox-elem/_macro.njk" import MdsCheckboxElem %}
6
+
6
7
  {%- if params.name -%}
7
8
  {%- set name = params.name -%}
8
9
  {%- else -%}
9
10
  {%- set name = params.id -%}
10
11
  {%- endif -%}
11
12
 
13
+ {% if params.helpText %}
14
+ {% set helpTextId = [params.id, '-help-text'] | join %}
15
+ {% endif %}
16
+
17
+ {% if params.validationError %}
18
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
19
+ {% endif %}
20
+
21
+ {% if helpTextId or validationErrorId or params.describedBy %}
22
+ {% set ariaDescribedBy = [validationErrorId, helpTextId, params.describedBy] | join(' ') | trim %}
23
+ {% endif %}
24
+
12
25
  {% macro createCheckboxes(checkboxParams) %}
13
26
  {% if checkboxParams.options and checkboxParams.options.length %}
14
27
  {% for option in checkboxParams.options %}
@@ -95,7 +108,7 @@
95
108
  {% endif %}
96
109
 
97
110
  <div class="mds-form-element mds-form-element--checkbox{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" id="{{params.id}}" data-test="checkbox{% if params.id %}-{{params.id}}{% endif %}">
98
- <fieldset {%- if params.describedBy %} aria-describedby="{{params.describedBy}}"{% endif %}>
111
+ <fieldset {%- if ariaDescribedBy %} aria-describedby="{{ariaDescribedBy}}"{% endif %}>
99
112
  {{ MdsInputLabel({
100
113
  element: 'legend',
101
114
  labelText: params.labelText,
@@ -107,7 +120,9 @@
107
120
  }) }}
108
121
  {{ MdsInputMessages({
109
122
  id: params.id,
123
+ helpTextId: helpTextId,
110
124
  helpText: params.helpText,
125
+ validationErrorId: validationErrorId,
111
126
  validationError: params.validationError
112
127
  }) }}
113
128
  <div class="mds-form-check-container{% if hasBorder %} mds-form-check-container--border{% endif %}">
@@ -18,6 +18,7 @@
18
18
  i18n: {
19
19
  requiredIcon: 'required', // visually hidden text for the required icon (label)
20
20
  loadingText: 'Loading', // visually hidden text for the loading icon
21
+ errorIcon: default is 'Error', // visually hidden text for the error icon
21
22
  describedByText:
22
23
  'When autocomplete results are available, use up and down arrows to review and enter to select.', // help text for screen readers users to explain how to use the combobox
23
24
  resultsMessage: '{count} result available.', // announce number of results - note the use of `{count}` to get the number of results
@@ -22,6 +22,18 @@
22
22
 
23
23
  {%- set labelId %}{{comboboxId}}-label{% endset -%}
24
24
 
25
+ {% if params.helpText %}
26
+ {% set helpTextId = [params.id, '-help-text'] | join %}
27
+ {% endif %}
28
+
29
+ {% if params.validationError %}
30
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
31
+ {% endif %}
32
+
33
+ {% if helpTextId or validationErrorId %}
34
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
35
+ {% endif %}
36
+
25
37
  {%- if comboboxId -%}
26
38
  <div class="mds-form-element mds-form-element--combobox js-mds-combobox{% if params.classes %} {{params.classes}}{% endif %}{% if params.state %} mds-form-element--{{params.state}}{% endif %}" data-combobox-id="{{ comboboxId }}" data-test="combobox{% if comboboxId %}-{{comboboxId}}{% endif %}" data-type="{{ params.type }}">
27
39
  {{ MdsInputLabel({
@@ -35,12 +47,20 @@
35
47
  }) }}
36
48
  {{ MdsInputMessages({
37
49
  id: comboboxId,
50
+ helpTextId: helpTextId,
38
51
  helpText: params.helpText,
52
+ validationErrorId: validationErrorId,
39
53
  validationError: params.validationError
40
54
  }) }}
41
55
  <div class="mds-form-element__fallback">
42
56
  {% if params.fallbackTo === 'select' and params.options %}
43
- <select class="mds-form-control" id="{{ comboboxId }}" name="{{ comboboxName }}" value="{{ params.defaultValue|default('') }}">
57
+ <select
58
+ class="mds-form-control"
59
+ id="{{ comboboxId }}"
60
+ name="{{ comboboxName }}"
61
+ value="{{ params.defaultValue|default('') }}"
62
+ {% if ariaDescribedBy %}aria-describedby="{{ariaDescribedBy}}"{% endif %}
63
+ >
44
64
  <option>{{ placeholder }}</option>
45
65
  {%- if params.options -%}
46
66
  {%- for value, option in params.options -%}
@@ -49,7 +69,17 @@
49
69
  {%- endif -%}
50
70
  </select>
51
71
  {% elseif params.fallbackTo === 'input' %}
52
- <input class="mds-form-control" type="text" name="{{ comboboxName }}" autocomplete="off" id="{{ comboboxId }}" value="{{ params.value|default('') }}" placeholder="{{ placeholder }}" {% if params.validationError %} aria-invalid="true" {% endif %}/>
72
+ <input
73
+ class="mds-form-control"
74
+ type="text"
75
+ name="{{ comboboxName }}"
76
+ autocomplete="off"
77
+ id="{{ comboboxId }}"
78
+ value="{{ params.value|default('') }}"
79
+ placeholder="{{ placeholder }}"
80
+ {% if params.validationError %}aria-invalid="true"{% endif %}
81
+ {% if ariaDescribedBy %}aria-describedby="{{ariaDescribedBy}}"{% endif %}
82
+ />
53
83
  {% endif %}
54
84
  </div>
55
85
  {# Leave the custom element at the bottom so it has access to the above elements on render #}
@@ -57,6 +87,7 @@
57
87
  i18n="{{ params.i18n | dump }}" data-aria-invalid="{{ params.validationError }}"
58
88
  {% if params.fallbackTo === 'input' %}name="{{ comboboxName }}"{% endif %}
59
89
  {% if params.value %}value="{{ params.value }}"{% endif %}
90
+ {% if ariaDescribedBy %} describedby-id="{{ariaDescribedBy}}"{% endif -%}
60
91
  ></mds-combobox>
61
92
  </div>
62
93
  {%- endif -%}
@@ -79,5 +79,20 @@ module.exports = {
79
79
  fallbackTo: 'input',
80
80
  },
81
81
  },
82
+ {
83
+ name: 'AJAX autocomplete prefilled with validation error',
84
+ context: {
85
+ useAutocomplete: true,
86
+ variantTitle: 'AJAX autocomplete prefilled with validation error',
87
+ name: 'keywords',
88
+ id: 'keywords-lookup-prefilled-validation-error',
89
+ labelText: 'Keywords:',
90
+ placeholder: 'eg. Testimonials',
91
+ value: 'Initial Value',
92
+ vModel: 'Initial Value',
93
+ fallbackTo: 'input',
94
+ validationError: 'There was an error',
95
+ },
96
+ },
82
97
  ],
83
98
  };
@@ -17,6 +17,8 @@
17
17
  classes: classes,
18
18
  placeholder: placeholder,
19
19
  type: type,
20
+ validationError: validationError,
21
+ helpText: helpText,
20
22
  i18n: i18n
21
23
  }) }}
22
24
  {#
@@ -17,7 +17,8 @@
17
17
  - `i18n`: Text to translate/customise (object) **optional**
18
18
  ```
19
19
  i18n: {
20
- requiredIcon: 'required',
20
+ requiredIcon: 'required', , // visually hidden text for the required icon
21
+ errorIcon: default is 'Error', // visually hidden text for the error icon
21
22
  defaultFileText: 'Drag and drop',
22
23
  buttonText: 'Choose a file',
23
24
  removeButtonText: 'Remove file',
@@ -19,6 +19,18 @@
19
19
  -}}
20
20
  {%- endset %}
21
21
 
22
+ {% if params.helpText %}
23
+ {% set helpTextId = [params.id, '-help-text'] | join %}
24
+ {% endif %}
25
+
26
+ {% if params.validationError %}
27
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
28
+ {% endif %}
29
+
30
+ {% if helpTextId or validationErrorId %}
31
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
32
+ {% endif %}
33
+
22
34
  <div class="mds-form-element mds-form-element--file{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}{% if params.value %} mds-form-element--selected-file{% endif %}" id="{{ params.id }}-container" data-test="input{% if params.id %}-{{params.id}}{% endif %}">
23
35
  {{ MdsInputLabel({
24
36
  labelText: params.labelText,
@@ -31,7 +43,9 @@
31
43
  {% if params.value %}<p class="mds-file-upload__selected-file-fallback">{{ params.i18n.fallbackSelectedFileText | default('Use ' + params.value + ' or upload a different file') }}</p>{% endif %}
32
44
  {{ MdsInputMessages({
33
45
  id: params.id,
46
+ helpTextId: helpTextId,
34
47
  helpText: params.helpText,
48
+ validationErrorId: validationErrorId,
35
49
  validationError: params.validationError
36
50
  }) }}
37
51
  <div class="mds-file-upload">
@@ -50,6 +64,9 @@
50
64
  {% if params.validationError %}
51
65
  aria-invalid="true"
52
66
  {% endif %}
67
+ {% if ariaDescribedBy %}
68
+ aria-describedby="{{ariaDescribedBy}}"
69
+ {% endif %}
53
70
  />
54
71
  <div class="mds-file-upload__input-controls" aria-live="assertive" aria-atomic="true">
55
72
  <div class="mds-file-upload__selection-state" aria-hidden="true">
@@ -20,5 +20,17 @@ module.exports = {
20
20
  },
21
21
  },
22
22
  },
23
+ {
24
+ name: 'Errored file input',
25
+ context: {
26
+ labelText: 'Error with uploaded file',
27
+ name: 'selected-file',
28
+ id: 'selected-file',
29
+ validationError: 'There was an error',
30
+ i18n: {
31
+ fallbackSelectedFileText: 'Use my saved CV or upload a different one',
32
+ },
33
+ },
34
+ },
23
35
  ],
24
36
  };
@@ -24,6 +24,7 @@
24
24
  ```
25
25
  i18n: {
26
26
  requiredIcon: 'required', // visually hidden text for the required icon (label)
27
+ errorIcon: default is 'Error', // visually hidden text for the error icon
27
28
  }
28
29
  ```
29
30
 
@@ -7,6 +7,18 @@
7
7
  {% set name = params.id %}
8
8
  {% endif %}
9
9
 
10
+ {% if params.helpText %}
11
+ {% set helpTextId = [params.id, '-help-text'] | join %}
12
+ {% endif %}
13
+
14
+ {% if params.validationError %}
15
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
16
+ {% endif %}
17
+
18
+ {% if helpTextId or validationErrorId %}
19
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
20
+ {% endif %}
21
+
10
22
  <div class="mds-form-element mds-form-element--input{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" id="{{ params.id }}-container" data-test="input{% if params.id %}-{{params.id}}{% endif %}">
11
23
  {{ MdsInputLabel({
12
24
  labelText: params.labelText,
@@ -18,7 +30,9 @@
18
30
  }) }}
19
31
  {{ MdsInputMessages({
20
32
  id: params.id,
33
+ helpTextId: helpTextId,
21
34
  helpText: params.helpText,
35
+ validationErrorId: validationErrorId,
22
36
  validationError: params.validationError
23
37
  }) }}
24
38
  <input
@@ -41,5 +55,8 @@
41
55
  {% if params.autocompleteValue %}
42
56
  autocomplete="{{ params.autocompleteValue }}"
43
57
  {% endif %}
58
+ {% if ariaDescribedBy %}
59
+ aria-describedby="{{ariaDescribedBy}}"
60
+ {% endif %}
44
61
  />
45
- </div>
62
+ </div>
@@ -18,6 +18,7 @@
18
18
  ```
19
19
  i18n: {
20
20
  requiredIcon: 'required', // visually hidden text for the required icon (label)
21
+ errorIcon: default is 'Error', // visually hidden text for the error icon
21
22
  }
22
23
  ```
23
24
 
@@ -7,8 +7,20 @@
7
7
  {%- set name = params.id -%}
8
8
  {%- endif -%}
9
9
 
10
+ {% if params.helpText %}
11
+ {% set helpTextId = [params.id, '-help-text'] | join %}
12
+ {% endif %}
13
+
14
+ {% if params.validationError %}
15
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
16
+ {% endif %}
17
+
18
+ {% if helpTextId or validationErrorId %}
19
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
20
+ {% endif %}
21
+
10
22
  <div class="mds-form-element mds-form-element--radio{% if params.classes %} {{params.classes}}{% endif %}" id="{{params.id}}" data-test="radio{% if params.id %}-{{params.id}}{% endif %}">
11
- <fieldset>
23
+ <fieldset {% if ariaDescribedBy %}aria-describedby="{{ariaDescribedBy}}"{% endif %}>
12
24
  {{ MdsInputLabel({
13
25
  element: 'legend',
14
26
  labelText: params.labelText,
@@ -20,7 +32,9 @@
20
32
  }) }}
21
33
  {{ MdsInputMessages({
22
34
  id: params.id,
35
+ helpTextId: helpTextId,
23
36
  helpText: params.helpText,
37
+ validationErrorId: validationErrorId,
24
38
  validationError: params.validationError
25
39
  }) }}
26
40
  {%- for radio in params.options -%}
@@ -67,5 +67,31 @@ module.exports = {
67
67
  ],
68
68
  },
69
69
  },
70
+ {
71
+ name: 'Error',
72
+ context: {
73
+ id: 'error-stacked-radio-input',
74
+ labelText: 'Error Stacked Radio',
75
+ validationError: 'There was an error',
76
+ helpText: "This field won't steal your card details",
77
+ options: [
78
+ {
79
+ labelText: 'Radio Input 1',
80
+ value: '4-1',
81
+ id: 'radio-4-1',
82
+ },
83
+ {
84
+ labelText: 'Radio Input 2',
85
+ value: '4-2',
86
+ id: 'radio-4-2',
87
+ },
88
+ {
89
+ labelText: 'Radio Input 3',
90
+ value: '4-3',
91
+ id: 'radio-4-3',
92
+ },
93
+ ],
94
+ },
95
+ },
70
96
  ],
71
97
  };
@@ -9,7 +9,9 @@
9
9
  value: value,
10
10
  disabled: disabled,
11
11
  options: options,
12
- classes: classes
12
+ classes: classes,
13
+ helpText: helpText,
14
+ validationError: validationError
13
15
  }) }}
14
16
  </div>
15
17
 
@@ -19,6 +19,7 @@
19
19
  ```
20
20
  i18n: {
21
21
  requiredIcon: 'required', // visually hidden text for the required icon (label)
22
+ errorIcon: default is 'Error', // visually hidden text for the error icon
22
23
  defaultOptionLabel: 'Please select', // text for default option - won't display if hideDefault parameter is set
23
24
  }
24
25
  ```
@@ -7,6 +7,18 @@
7
7
  {% set name = params.id %}
8
8
  {% endif %}
9
9
 
10
+ {% if params.helpText %}
11
+ {% set helpTextId = [params.id, '-help-text'] | join %}
12
+ {% endif %}
13
+
14
+ {% if params.validationError %}
15
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
16
+ {% endif %}
17
+
18
+ {% if helpTextId or validationErrorId %}
19
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
20
+ {% endif %}
21
+
10
22
  <div
11
23
  class="mds-form-element mds-form-element--select
12
24
  {%- if params.classes %} {{params.classes}}{% endif -%}
@@ -24,16 +36,21 @@
24
36
  }) }}
25
37
  {{ MdsInputMessages({
26
38
  id: params.id,
39
+ helpTextId: helpTextId,
27
40
  helpText: params.helpText,
41
+ validationErrorId: validationErrorId,
28
42
  validationError: params.validationError
29
43
  }) }}
30
44
  <select
31
45
  name="{{name}}"
32
46
  id="{{params.id}}"
47
+ class="mds-form-control"
33
48
  {%- if params.disabled %}
34
49
  disabled="disabled"
35
50
  {% endif -%}
36
- class="mds-form-control"
51
+ {% if ariaDescribedBy %}
52
+ aria-describedby="{{ariaDescribedBy}}"
53
+ {% endif %}
37
54
  >
38
55
  {% if not params.hideDefault -%}
39
56
  <option {%- if not params.value %} selected="selected"{% endif %} value="">
@@ -96,5 +96,29 @@ module.exports = {
96
96
  },
97
97
  },
98
98
  },
99
+ {
100
+ name: 'Select Input With Error',
101
+ context: {
102
+ labelText: 'Select Input With Error',
103
+ name: 'Select input with error',
104
+ id: 'select-input-with-error',
105
+ optional: true,
106
+ validationError: 'There was an error',
107
+ options: [
108
+ {
109
+ labelText: 'Option 1',
110
+ value: 'option-1',
111
+ },
112
+ {
113
+ labelText: 'Option 2',
114
+ value: 'option-2',
115
+ },
116
+ {
117
+ labelText: 'Option 3',
118
+ value: 'option-3',
119
+ },
120
+ ],
121
+ },
122
+ },
99
123
  ],
100
124
  };
@@ -64,5 +64,6 @@ This input relies entirely on the browser standard checkbox input and applies th
64
64
  ```
65
65
  i18n: {
66
66
  requiredIcon: 'required', // visually hidden text for the required icon (label)
67
+ errorIcon: default is 'Error', // visually hidden text for the error icon
67
68
  }
68
69
  ```
@@ -23,10 +23,24 @@
23
23
  {%- set isSelected = true -%}
24
24
  {%- endif -%}
25
25
 
26
+ {% if params.helpText %}
27
+ {% set helpTextId = [params.id, '-help-text'] | join %}
28
+ {% endif %}
29
+
30
+ {% if params.validationError %}
31
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
32
+ {% endif %}
33
+
34
+ {% if helpTextId or validationErrorId or params.describedBy %}
35
+ {% set ariaDescribedBy = [validationErrorId, helpTextId, params.describedBy] | join(' ') | trim %}
36
+ {% endif %}
37
+
26
38
  <div class="mds-form-element mds-form-element--checkbox{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" data-test="checkbox{% if params.id %}-{{params.id}}{% endif %}">
27
39
  {{- MdsInputMessages({
28
40
  id: params.id,
41
+ helpTextId: helpTextId,
29
42
  helpText: params.helpText,
43
+ validationErrorId: validationErrorId,
30
44
  validationError: params.validationError
31
45
  }) -}}
32
46
  <div class="mds-form-check-container">
@@ -35,7 +49,7 @@
35
49
  disabled: params.disabled,
36
50
  isSelected: isSelected,
37
51
  labelText: options.labelText,
38
- describedBy: params.describedBy,
52
+ describedBy: ariaDescribedBy,
39
53
  optional: params.optional,
40
54
  name: name,
41
55
  id: id,
@@ -44,4 +58,4 @@
44
58
  }) -}}
45
59
  </div>
46
60
  </div>
47
- </div>
61
+ </div>
@@ -42,5 +42,20 @@ module.exports = {
42
42
  ],
43
43
  },
44
44
  },
45
+ {
46
+ name: 'Checkbox with validation error',
47
+ context: {
48
+ id: 'error',
49
+ validationError: 'There was an error',
50
+ describedBy: 'topcv-example',
51
+ options: [
52
+ {
53
+ labelText: 'Please tick here to receive a free CV review from TopCV',
54
+ value: 'data-yes',
55
+ id: 'data-error',
56
+ },
57
+ ],
58
+ },
59
+ },
45
60
  ],
46
61
  };
@@ -36,27 +36,35 @@
36
36
  disabled: {{disabled or false}},
37
37
  isChecked: false,
38
38
  helpText: "{{helpText or ''}}",
39
+ error: {{state === 'error'}},
39
40
  validationError: "{{validationError or ''}}",
40
- error: {{state === 'error'}}
41
-
41
+ describedBy: "{{describedBy or ''}}"
42
42
  };
43
43
  },
44
+ methods: {
45
+ createDescribedBy(ids) {
46
+ return [this.describedBy, ...ids].filter(id => !!id).join(' ');
47
+ }
48
+ },
44
49
  template: `<div>
45
50
  <MdsFormItem :error="error">
46
51
  <template v-if="validationError" #error>{{validationError}}</template>
47
52
  <template v-if="helpText" #help>{{helpText}}</template>
48
- <MdsSingleCheckbox
49
- id="{{id}}-vue-version"
50
- name="{{name}}"
51
- describedBy="{{describedBy}}"
52
- classes="{{classes}}"
53
- state="{{state}}"
54
- :value="option.value"
55
- v-model="isChecked"
56
- :disabled="disabled"
57
- :optional="optional"
58
- :i18n="i18n" >{{option.labelText | safe}}</MdsSingleCheckbox>
59
- </MdsFormItem>
53
+ <template #default="slotProps">
54
+ <MdsSingleCheckbox
55
+ id="{{id}}-vue-version"
56
+ name="{{name}}"
57
+ :describedBy="createDescribedBy([slotProps.errorMessageId, slotProps.helpMessageId])"
58
+ classes="{{classes}}"
59
+ state="{{state}}"
60
+ :value="option.value"
61
+ v-model="isChecked"
62
+ :disabled="disabled"
63
+ :optional="optional"
64
+ :i18n="i18n" >{{option.labelText | safe}}
65
+ </MdsSingleCheckbox>
66
+ </template>
67
+ </MdsFormItem>
60
68
  </div>`
61
69
 
62
70
  }).use(MdsLibrary).mount('#vue-{{id}}');
@@ -64,5 +72,9 @@
64
72
 
65
73
  </div>
66
74
 
75
+ {% if id === "error" %}
76
+ <div id="topcv-example">Learn more about TopCV.</div>
77
+ {% endif %}
78
+
67
79
 
68
80
  <div style="margin-bottom:40px"></div>
@@ -30,6 +30,7 @@ Buttons currently available:
30
30
  ```
31
31
  i18n: {
32
32
  requiredIcon: 'required', // visually hidden text for the required icon
33
+ errorIcon: default is 'Error', // visually hidden text for the error icon
33
34
  toolbarLabel: 'Text formatting', // label for the toolbar explaining what the toolbar is about (default: Text formatting)
34
35
  }
35
36
  ```
@@ -2,6 +2,18 @@
2
2
  {% from "../_message/_macro.njk" import MdsInputMessages %}
3
3
  {% from "../../icons/_macro.njk" import MdsIcon %}
4
4
 
5
+ {% if params.helpText %}
6
+ {% set helpTextId = [params.id, '-help-text'] | join %}
7
+ {% endif %}
8
+
9
+ {% if params.validationError %}
10
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
11
+ {% endif %}
12
+
13
+ {% if helpTextId or validationErrorId %}
14
+ {% set ariaDescribedBy = [validationErrorId, helpTextId] | join(' ') | trim %}
15
+ {% endif %}
16
+
5
17
  <div class="mds-form-element mds-form-element--text-editor{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}" id="{{ params.id }}-container" data-test="text-editor{% if params.id %}-{{params.id}}{% endif %}">
6
18
  {{ MdsInputLabel({
7
19
  id: "text-editor-label-" + params.id,
@@ -14,7 +26,9 @@
14
26
  }) }}
15
27
  {{ MdsInputMessages({
16
28
  id: params.id,
29
+ helpTextId: helpTextId,
17
30
  helpText: params.helpText,
31
+ validationErrorId: validationErrorId,
18
32
  validationError: params.validationError
19
33
  }) }}
20
34
  <textarea
@@ -24,6 +38,9 @@
24
38
  {%- if params.validationError %}
25
39
  aria-invalid="true"
26
40
  {% endif -%}
41
+ {% if ariaDescribedBy %}
42
+ aria-describedby="{{ariaDescribedBy}}"
43
+ {% endif %}
27
44
  >{#
28
45
  #}{% if params.value %}{{params.value}}{% endif %}{#
29
46
  #}</textarea>
@@ -33,6 +50,7 @@
33
50
  iconpath="{{ defaultIconPath }}"
34
51
  {%- if params.menuButtons %} menu-buttons="{{ params.menuButtons | dump }}"{% endif -%}
35
52
  {%- if params.i18n %} i18n="{{ params.i18n | dump }}"{% endif -%}
36
- {%- if params.value %} value="{{ params.value }}"{% endif -%}>
53
+ {%- if params.value %} value="{{ params.value }}"{% endif -%}
54
+ {% if ariaDescribedBy %} describedby-id="{{ariaDescribedBy}}"{% endif -%}>
37
55
  </mds-text-editor>
38
56
  </div>
@@ -19,6 +19,7 @@
19
19
  ```
20
20
  i18n: {
21
21
  requiredIcon: 'required', // visually hidden text for the required icon (label)
22
+ errorIcon: default is 'Error', // visually hidden text for the error icon
22
23
  characterCountText: '<span class="js-character-count-number">[maxlength]</span> characters remaining' (use with the maxlength parameter)
23
24
  }
24
25
  ```
@@ -8,6 +8,22 @@
8
8
  {% set name = params.id %}
9
9
  {% endif %}
10
10
 
11
+ {% if params.maxlength %}
12
+ {% set characterCountId = [params.id, '-character-count-text'] | join %}
13
+ {% endif %}
14
+
15
+ {% if params.helpText %}
16
+ {% set helpTextId = [params.id, '-help-text'] | join %}
17
+ {% endif %}
18
+
19
+ {% if params.validationError %}
20
+ {% set validationErrorId = [params.id, '-validation-error'] | join %}
21
+ {% endif %}
22
+
23
+ {% if characterCountId or helpTextId or validationErrorId %}
24
+ {% set ariaDescribedBy = [validationErrorId, helpTextId, characterCountId] | join(' ') | trim %}
25
+ {% endif %}
26
+
11
27
  <div class="mds-form-element mds-form-element--textarea{% if params.state %} mds-form-element--{{params.state}}{% endif %}{% if params.classes %} {{params.classes}}{% endif %}{% if params.maxlength %} mds-form-element--character-count{% endif %}" id="{{ params.id }}-container" data-test="textarea{% if params.id %}-{{params.id}}{% endif %}">
12
28
  {{ MdsInputLabel({
13
29
  labelText: params.labelText,
@@ -19,7 +35,9 @@
19
35
  }) }}
20
36
  {{ MdsInputMessages({
21
37
  id: params.id,
38
+ helpTextId: helpTextId,
22
39
  helpText: params.helpText,
40
+ validationErrorId: validationErrorId,
23
41
  validationError: params.validationError
24
42
  }) }}
25
43
  <textarea
@@ -33,7 +51,10 @@
33
51
  placeholder="{% if params.placeholder %}{{ params.placeholder }}{% else %}{{ params.labelText }}{% endif %}"
34
52
  {% endif %}
35
53
  {% if params.maxlength %}
36
- maxlength="{{ params.maxlength }}" aria-describedby="{{ params.id }}-character-count-text"
54
+ maxlength="{{ params.maxlength }}"
55
+ {% endif %}
56
+ {% if ariaDescribedBy %}
57
+ aria-describedby="{{ ariaDescribedBy }}"
37
58
  {% endif %}
38
59
  {% if params.validationError %}
39
60
  aria-invalid="true"