@madgex/design-system 14.0.0 → 14.0.2

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.
@@ -1 +1 @@
1
- [{"name":"add"},{"name":"arrow-left"},{"name":"arrow-right"},{"name":"calendar"},{"name":"asterisk"},{"name":"cart"},{"name":"check"},{"name":"chevron-down"},{"name":"chevron-left"},{"name":"chevron-up"},{"name":"chevron-right"},{"name":"close"},{"name":"cross"},{"name":"doc-pdf"},{"name":"doc"},{"name":"email"},{"name":"external"},{"name":"flag"},{"name":"information"},{"name":"job"},{"name":"list-bullets"},{"name":"list-numbers"},{"name":"location-pin"},{"name":"menu"},{"name":"minus"},{"name":"plus-small"},{"name":"plus"},{"name":"question-mark"},{"name":"redo"},{"name":"remove"},{"name":"search"},{"name":"settings"},{"name":"share"},{"name":"social-facebook"},{"name":"social-linkedin"},{"name":"social-pinterest"},{"name":"social-reddit"},{"name":"social-twitter"},{"name":"spinner"},{"name":"star-fill"},{"name":"star-outline"},{"name":"text-bold"},{"name":"text-italic"},{"name":"text-link"},{"name":"text-strike-through"},{"name":"text-underline"},{"name":"triangle-down"},{"name":"triangle-right"},{"name":"triangle-up"},{"name":"undo"},{"name":"upload"},{"name":"user"}]
1
+ [{"name":"add"},{"name":"arrow-left"},{"name":"arrow-right"},{"name":"asterisk"},{"name":"calendar"},{"name":"cart"},{"name":"check"},{"name":"chevron-down"},{"name":"chevron-left"},{"name":"chevron-right"},{"name":"chevron-up"},{"name":"close"},{"name":"cross"},{"name":"doc-pdf"},{"name":"doc"},{"name":"email"},{"name":"external"},{"name":"flag"},{"name":"information"},{"name":"job"},{"name":"list-bullets"},{"name":"list-numbers"},{"name":"location-pin"},{"name":"menu"},{"name":"minus"},{"name":"plus-small"},{"name":"plus"},{"name":"question-mark"},{"name":"redo"},{"name":"remove"},{"name":"search"},{"name":"settings"},{"name":"share"},{"name":"social-facebook"},{"name":"social-linkedin"},{"name":"social-pinterest"},{"name":"social-reddit"},{"name":"social-twitter"},{"name":"spinner"},{"name":"star-fill"},{"name":"star-outline"},{"name":"text-bold"},{"name":"text-italic"},{"name":"text-link"},{"name":"text-strike-through"},{"name":"text-underline"},{"name":"triangle-down"},{"name":"triangle-right"},{"name":"triangle-up"},{"name":"undo"},{"name":"upload"},{"name":"user"}]
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@madgex/design-system",
3
3
  "author": "Madgex",
4
4
  "license": "UNLICENSED",
5
- "version": "14.0.0",
5
+ "version": "14.0.2",
6
6
  "main": "dist/js/index.js",
7
7
  "exports": {
8
8
  ".": "./dist/js/index.js",
@@ -20,7 +20,7 @@ Options can be provided via the `options` parameter, or obtained from an API usi
20
20
  - `optionLabelPath`: where to grab the visual label from the option object e.g. 'label' or 'title' or 'nested.object.label' (defaults to `label`)
21
21
  - `optionValuePath`: where to grab the value from the option object e.g. `value` or `nested.object.value` (defaults to `value`)
22
22
  - `multiple`: Boolean, whether to treat `value` input and output as an Array, or a singular. Also to display pills. default `false`
23
- - `fallbackTo`: the form element to use as a fallback. Should be either 'select' or 'input' **recommended**
23
+ - `fallbackTo`: the form element to use as a fallback. Should be either 'select' or 'input' **recommended** (see notes underneath)
24
24
  - `placeholder`: the placeholder for your input (defaults to 'Please select') **recommended**
25
25
  - `classes`: add extra classes to the trigger
26
26
  - `helpText`: Helper text to display under the label
@@ -56,6 +56,16 @@ The params `value`, `options`, `optionLabelPath` and `optionValuePath` are tight
56
56
  - `options`: an array of objects, each object has the property stated by `optionLabelPath` and `optionValuePath`
57
57
  - `value`: an object ( or array of objects if `multiple:true`), object is the same shape as the ones in `options`, each object has the property stated by `optionLabelPath` and `optionValuePath`
58
58
 
59
+ ## Fallback
60
+
61
+ When JavaScript is unavailable, the combobox will gracefully degrade to a native form element. Use the `fallbackTo` parameter to specify which fallback element to use: either a native `select` dropdown or a text `input`.
62
+
63
+ Both fallback elements share the same `id` as the combobox to ensure the label remains properly associated. However, the fallback's `name` attribute will be `[name]_fallback` to distinguish it from the JavaScript-enabled version. This allows your server-side code to detect when the fallback was used and handle the form submission appropriately.
64
+
65
+ **Choosing a fallback type:**
66
+ - Use `fallbackTo: 'select'` when you have a static, predefined list of options that work well in a standard dropdown.
67
+ - Use `fallbackTo: 'input'` when options are dynamic (from an API) or when you prefer a text input. With a text input fallback, users can type and submit values that your server can then process (e.g., look up a location ID from a location name).
68
+
59
69
  ### Example - Single mode - no API - default option object shape
60
70
 
61
71
  As our options object uses the default property names, we don't need to specify them.
@@ -1,25 +1,9 @@
1
- {% from "../label/_macro.njk" import MdsInputLabel %}
2
- {% from "../_message/_macro.njk" import MdsInputMessages %}
3
- {% from "../../../sub-components/attributes/macro.njk" import MdsAttributes %}
1
+ {%- from "../label/_macro.njk" import MdsInputLabel -%}
2
+ {%- from "../_message/_macro.njk" import MdsInputMessages -%}
3
+ {%- from "../../../sub-components/attributes/macro.njk" import MdsAttributes -%}
4
4
 
5
- {%- set comboboxId %}
6
- {%- if params.id -%}
7
- {{ params.id }}
8
- {%- else -%}
9
- {#
10
- if the id is missing it will be constructed using:
11
- [component name]-[item labelText]-[index]
12
- e.g. period-next-week-2
13
- #}
14
- {%- if params.name -%}{{ params.name | lower | trim | replace(' ', '-')}}{%- else -%}{{ params.labelText | lower | trim | replace(' ', '-') }}{%- endif -%}
15
- {%- endif -%}
16
- {% endset -%}
17
-
18
- {% if params.name %}
19
- {% set comboboxName = params.name %}
20
- {% else %}
21
- {% set comboboxName = comboboxId %}
22
- {% endif %}
5
+ {%- set comboboxId = params.id if params.id else params.name -%}
6
+ {%- set comboboxName = params.name if params.name else params.id -%}
23
7
 
24
8
  {%- set labelId %}{{comboboxId}}-label{% endset -%}
25
9
 
@@ -86,7 +70,7 @@
86
70
  <select
87
71
  class="mds-form-control"
88
72
  id="{{ comboboxId }}"
89
- name="{{ comboboxName }}"
73
+ name="{{ comboboxName }}_fallback"
90
74
  {% if params.multiple %}multiple{% endif %}
91
75
  {% if ariaDescribedBy %}aria-describedby="{{ariaDescribedBy}}"{% endif %}
92
76
  >
@@ -109,11 +93,11 @@
109
93
  {%- endif -%}
110
94
  </select>
111
95
  {# we cant have multiple mode and use input #}
112
- {% elseif not params.multiple and params.fallbackTo === 'input' %}
96
+ {% elseif params.fallbackTo === 'input' %}
113
97
  <input
114
98
  class="mds-form-control"
115
99
  type="text"
116
- name="{{ comboboxName }}"
100
+ name="{{ comboboxName }}_fallback"
117
101
  autocomplete="off"
118
102
  id="{{ comboboxId }}"
119
103
  {% if params.value %} value="{{params.value[_optionValuePath]}}"{% endif %}
@@ -121,14 +105,11 @@
121
105
  {% if params.validationError %}aria-invalid="true"{% endif %}
122
106
  {% if ariaDescribedBy %}aria-describedby="{{ariaDescribedBy}}"{% endif %}
123
107
  />
124
- {% elseif params.multiple and params.fallbackTo === 'input' %}
125
- <strong>YOU MUST USE `select` AS `fallbackTo` WHEN USING `multiple` MODE</strong>
126
108
  {% endif %}
127
109
  </div>
128
110
  {% if caller %}
129
111
  {{- caller() -}}
130
112
  {% endif %}
131
113
  </mds-combobox>
132
- <br><br>
133
114
  </div>
134
115
  {%- endif -%}
@@ -109,7 +109,7 @@ module.exports = {
109
109
  id: 'keywords-lookup-multiselect-preselected',
110
110
  labelText: 'Keywords:',
111
111
  placeholder: 'eg. Web developer',
112
- fallbackTo: 'select',
112
+ fallbackTo: 'input',
113
113
  minSearchCharacters: 3,
114
114
  apiUrl: 'https://api.datamuse.com/sug',
115
115
  apiQueryKey: 's',
@@ -1,7 +1,7 @@
1
1
  {% from "./inputs/combobox/_macro.njk" import MdsCombobox %}
2
2
 
3
3
  <form class="mds-grid-row">
4
- <div class="mds-grid-col-6">
4
+ <div class="mds-grid-col-6 mds-margin-bottom-b10">
5
5
  <h3>{{ variantTitle }}</h3>
6
6
 
7
7
  {% call MdsCombobox({
@@ -25,7 +25,7 @@
25
25
  apiOptionsPath: apiOptionsPath,
26
26
  optionLabelPath: optionLabelPath,
27
27
  optionValuePath: optionValuePath,
28
- multiple: multiple
28
+ multiple: multiple,
29
29
  attributes: attributes
30
30
  }) %}
31
31
  {% endcall %}