govuk_publishing_components 65.1.0 → 65.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/component_guide/application.scss +13 -15
- data/app/assets/stylesheets/govuk_publishing_components/all-components.scss +0 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss +25 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_details.scss +34 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/_heading.scss +1 -0
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_markdown-typography.scss +4 -0
- data/app/assets/stylesheets/govuk_publishing_components/specific-components.scss +0 -1
- data/app/controllers/govuk_publishing_components/applications_page_controller.rb +1 -1
- data/app/controllers/govuk_publishing_components/audit_controller.rb +0 -1
- data/app/models/govuk_publishing_components/component_doc.rb +10 -3
- data/app/models/govuk_publishing_components/component_wrapper_helper_options.rb +4 -2
- data/app/views/govuk_publishing_components/component_guide/component_doc/_component.html.erb +1 -1
- data/app/views/govuk_publishing_components/component_guide/component_doc/_preview.html.erb +2 -2
- data/app/views/govuk_publishing_components/component_guide/show.html.erb +47 -33
- data/app/views/govuk_publishing_components/components/_details.html.erb +4 -0
- data/app/views/govuk_publishing_components/components/_devolved_nations.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_option_select.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/docs/details.yml +16 -0
- data/lib/govuk_publishing_components/presenters/devolved_nations_helper.rb +13 -7
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/choices.js/README.md +140 -30
- data/node_modules/choices.js/package.json +10 -13
- data/node_modules/choices.js/public/assets/scripts/choices.js +144 -89
- data/node_modules/choices.js/public/assets/scripts/choices.min.js +2 -2
- data/node_modules/choices.js/public/assets/scripts/choices.mjs +144 -89
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.js +144 -86
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.min.js +2 -2
- data/node_modules/choices.js/public/assets/scripts/choices.search-basic.mjs +144 -86
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.js +139 -77
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.min.js +2 -2
- data/node_modules/choices.js/public/assets/scripts/choices.search-kmp.mjs +139 -77
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.js +137 -76
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.min.js +2 -2
- data/node_modules/choices.js/public/assets/scripts/choices.search-prefix.mjs +137 -76
- data/node_modules/choices.js/public/assets/styles/base.css +39 -9
- data/node_modules/choices.js/public/assets/styles/base.css.map +1 -1
- data/node_modules/choices.js/public/assets/styles/base.min.css +1 -1
- data/node_modules/choices.js/public/assets/styles/choices.css +93 -95
- data/node_modules/choices.js/public/assets/styles/choices.css.map +1 -1
- data/node_modules/choices.js/public/assets/styles/choices.min.css +1 -1
- data/node_modules/choices.js/public/types/src/scripts/choices.d.ts +11 -0
- data/node_modules/choices.js/public/types/src/scripts/components/container.d.ts +2 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/choice-full.d.ts +2 -1
- data/node_modules/choices.js/public/types/src/scripts/interfaces/class-names.d.ts +2 -0
- data/node_modules/choices.js/public/types/src/scripts/interfaces/input-choice.d.ts +2 -1
- data/node_modules/choices.js/public/types/src/scripts/interfaces/options.d.ts +19 -3
- data/node_modules/choices.js/public/types/src/scripts/interfaces/store.d.ts +2 -1
- data/node_modules/choices.js/public/types/src/scripts/interfaces/types.d.ts +2 -1
- data/node_modules/choices.js/public/types/src/scripts/lib/utils.d.ts +3 -1
- data/node_modules/choices.js/src/scripts/choices.ts +110 -64
- data/node_modules/choices.js/src/scripts/components/container.ts +8 -0
- data/node_modules/choices.js/src/scripts/components/wrapped-select.ts +3 -1
- data/node_modules/choices.js/src/scripts/defaults.ts +12 -7
- data/node_modules/choices.js/src/scripts/interfaces/choice-full.ts +2 -1
- data/node_modules/choices.js/src/scripts/interfaces/class-names.ts +2 -0
- data/node_modules/choices.js/src/scripts/interfaces/event-choice.ts +1 -0
- data/node_modules/choices.js/src/scripts/interfaces/input-choice.ts +4 -2
- data/node_modules/choices.js/src/scripts/interfaces/options.ts +21 -3
- data/node_modules/choices.js/src/scripts/interfaces/store.ts +2 -1
- data/node_modules/choices.js/src/scripts/interfaces/types.ts +3 -1
- data/node_modules/choices.js/src/scripts/lib/utils.ts +27 -4
- data/node_modules/choices.js/src/scripts/search/kmp.ts +2 -1
- data/node_modules/choices.js/src/scripts/store/store.ts +4 -1
- data/node_modules/choices.js/src/scripts/templates.ts +6 -3
- data/node_modules/choices.js/src/styles/base.scss +42 -9
- data/node_modules/choices.js/src/styles/choices.scss +119 -93
- metadata +2 -3
- data/app/assets/stylesheets/govuk_publishing_components/components/helpers/_contents-list-helper.scss +0 -24
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Choices.js [](https://github.com/Choices-js/Choices/actions) [](https://github.com/Choices-js/Choices/actions) [](https://www.npmjs.com/package/choices.js)
|
|
2
2
|
|
|
3
3
|
A vanilla, lightweight (~20kb gzipped 🎉), configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.
|
|
4
4
|
|
|
@@ -45,6 +45,7 @@ A vanilla, lightweight (~20kb gzipped 🎉), configurable select box/text input
|
|
|
45
45
|
- [Callbacks](#callbacks)
|
|
46
46
|
- [Events](#events)
|
|
47
47
|
- [Methods](#methods)
|
|
48
|
+
- [CSS custom properties](#css-custom-properties)
|
|
48
49
|
- [Development](#development)
|
|
49
50
|
- [License](#license)
|
|
50
51
|
|
|
@@ -64,8 +65,9 @@ yarn add choices.js
|
|
|
64
65
|
|
|
65
66
|
From a [CDN](https://www.jsdelivr.com/package/npm/choices.js):
|
|
66
67
|
|
|
67
|
-
**
|
|
68
|
-
|
|
68
|
+
**Notes:**
|
|
69
|
+
* There is sometimes a delay before the latest version of Choices is reflected on the CDN.
|
|
70
|
+
* Examples below pin a version (v11.1.0). Check [latest release](https://www.jsdelivr.com/package/npm/choices.js) and update v11.1.0 to the latest tag before using.
|
|
69
71
|
```html
|
|
70
72
|
<!-- Include base CSS (optional) -->
|
|
71
73
|
<link
|
|
@@ -75,7 +77,7 @@ From a [CDN](https://www.jsdelivr.com/package/npm/choices.js):
|
|
|
75
77
|
<!-- Or versioned -->
|
|
76
78
|
<link
|
|
77
79
|
rel="stylesheet"
|
|
78
|
-
href="https://cdn.jsdelivr.net/npm/choices.js@
|
|
80
|
+
href="https://cdn.jsdelivr.net/npm/choices.js@11.1.0/public/assets/styles/base.min.css"
|
|
79
81
|
/>
|
|
80
82
|
|
|
81
83
|
<!-- Include Choices CSS -->
|
|
@@ -86,13 +88,13 @@ From a [CDN](https://www.jsdelivr.com/package/npm/choices.js):
|
|
|
86
88
|
<!-- Or versioned -->
|
|
87
89
|
<link
|
|
88
90
|
rel="stylesheet"
|
|
89
|
-
href="https://cdn.jsdelivr.net/npm/choices.js@
|
|
91
|
+
href="https://cdn.jsdelivr.net/npm/choices.js@11.1.0/public/assets/styles/choices.min.css"
|
|
90
92
|
/>
|
|
91
93
|
|
|
92
94
|
<!-- Include Choices JavaScript (latest) -->
|
|
93
95
|
<script src="https://cdn.jsdelivr.net/npm/choices.js/public/assets/scripts/choices.min.js"></script>
|
|
94
96
|
<!-- Or versioned -->
|
|
95
|
-
<script src="https://cdn.jsdelivr.net/npm/choices.js@
|
|
97
|
+
<script src="https://cdn.jsdelivr.net/npm/choices.js@11.1.0/public/assets/scripts/choices.min.js"></script>
|
|
96
98
|
```
|
|
97
99
|
|
|
98
100
|
Or include Choices directly:
|
|
@@ -159,6 +161,7 @@ import "choices.js/public/assets/styles/choices.css";
|
|
|
159
161
|
paste: true,
|
|
160
162
|
searchEnabled: true,
|
|
161
163
|
searchChoices: true,
|
|
164
|
+
searchDisabledChoices: false,
|
|
162
165
|
searchFloor: 1,
|
|
163
166
|
searchResultLimit: 4,
|
|
164
167
|
searchFields: ['label', 'value'],
|
|
@@ -166,7 +169,7 @@ import "choices.js/public/assets/styles/choices.css";
|
|
|
166
169
|
resetScrollPosition: true,
|
|
167
170
|
shouldSort: true,
|
|
168
171
|
shouldSortItems: false,
|
|
169
|
-
sorter: () =>
|
|
172
|
+
sorter: (a, b) => sortByAlpha,
|
|
170
173
|
shadowRoot: null,
|
|
171
174
|
placeholder: true,
|
|
172
175
|
placeholderValue: null,
|
|
@@ -174,17 +177,18 @@ import "choices.js/public/assets/styles/choices.css";
|
|
|
174
177
|
prependValue: null,
|
|
175
178
|
appendValue: null,
|
|
176
179
|
renderSelectedChoices: 'auto',
|
|
180
|
+
searchRenderSelectedChoices: true,
|
|
177
181
|
loadingText: 'Loading...',
|
|
178
182
|
noResultsText: 'No results found',
|
|
179
183
|
noChoicesText: 'No choices to choose from',
|
|
180
184
|
itemSelectText: 'Press to select',
|
|
181
185
|
uniqueItemText: 'Only unique values can be added',
|
|
182
186
|
customAddItemText: 'Only values matching specific conditions can be added',
|
|
183
|
-
addItemText: (value) => {
|
|
187
|
+
addItemText: (value, rawValue) => {
|
|
184
188
|
return `Press Enter to add <b>"${value}"</b>`;
|
|
185
189
|
},
|
|
186
190
|
removeItemIconText: () => `Remove item`,
|
|
187
|
-
removeItemLabelText: (value) => `Remove item: ${value}`,
|
|
191
|
+
removeItemLabelText: (value, rawValue) => `Remove item: ${value}`,
|
|
188
192
|
maxItemText: (maxItemCount) => {
|
|
189
193
|
return `Only ${maxItemCount} values can be added`;
|
|
190
194
|
},
|
|
@@ -217,6 +221,7 @@ import "choices.js/public/assets/styles/choices.css";
|
|
|
217
221
|
selectedState: ['is-selected'],
|
|
218
222
|
flippedState: ['is-flipped'],
|
|
219
223
|
loadingState: ['is-loading'],
|
|
224
|
+
invalidState: ['is-invalid'],
|
|
220
225
|
notice: ['choices__notice'],
|
|
221
226
|
addChoice: ['choices__item--selectable', 'add-choice'],
|
|
222
227
|
noResults: ['has-no-results'],
|
|
@@ -480,6 +485,14 @@ Pass an array of objects:
|
|
|
480
485
|
|
|
481
486
|
**Usage:** Whether choices should be filtered by input or not. If `false`, the search event will still emit, but choices will not be filtered.
|
|
482
487
|
|
|
488
|
+
### searchDisabledChoices
|
|
489
|
+
|
|
490
|
+
**Type:** `Boolean` **Default:** `false`
|
|
491
|
+
|
|
492
|
+
**Input types affected:** `select-one`, `select-multiple`
|
|
493
|
+
|
|
494
|
+
**Usage:** Whether disabled choices should be included in search results. If `true`, disabled choices will appear in search results but still cannot be selected. This is useful when you want users to see what options exist but are currently unavailable. Placeholders are always excluded from search results regardless of this setting.
|
|
495
|
+
|
|
483
496
|
### searchFields
|
|
484
497
|
|
|
485
498
|
**Type:** `Array/String` **Default:** `['label', 'value']`
|
|
@@ -596,7 +609,7 @@ const example = new Choices(element, {
|
|
|
596
609
|
sorter: function(a, b) {
|
|
597
610
|
return b.label.length - a.label.length;
|
|
598
611
|
},
|
|
599
|
-
};
|
|
612
|
+
});
|
|
600
613
|
```
|
|
601
614
|
|
|
602
615
|
### placeholder
|
|
@@ -659,6 +672,23 @@ For backward compatibility, `<option value="">This is a placeholder</option>` an
|
|
|
659
672
|
|
|
660
673
|
**Usage:** Whether selected choices should be removed from the list. By default choices are removed when they are selected in multiple select box. To always render choices pass `always`.
|
|
661
674
|
|
|
675
|
+
### searchRenderSelectedChoices
|
|
676
|
+
|
|
677
|
+
**Type:** `Boolean` **Default:** `true'`
|
|
678
|
+
|
|
679
|
+
**Input types affected:** `select-multiple`
|
|
680
|
+
|
|
681
|
+
**Usage:** Whether selected choices should be removed from the list during search.
|
|
682
|
+
|
|
683
|
+
**Example:**
|
|
684
|
+
|
|
685
|
+
```js
|
|
686
|
+
// Hide selected choices from search results
|
|
687
|
+
const example = new Choices(element, {
|
|
688
|
+
searchRenderSelectedChoices: false,
|
|
689
|
+
});
|
|
690
|
+
```
|
|
691
|
+
|
|
662
692
|
### loadingText
|
|
663
693
|
|
|
664
694
|
**Type:** `String` **Default:** `Loading...`
|
|
@@ -693,45 +723,47 @@ For backward compatibility, `<option value="">This is a placeholder</option>` an
|
|
|
693
723
|
|
|
694
724
|
### addItemText
|
|
695
725
|
|
|
696
|
-
**Type:** `String/Function` **Default:** `Press Enter to add "${value}"`
|
|
726
|
+
**Type:** `String/Function` **Default:** `Press Enter to add "${value}"` **Arguments:** `value`, `valueRaw`
|
|
697
727
|
|
|
698
728
|
**Input types affected:** `text`, `select-one`, `select-multiple`
|
|
699
729
|
|
|
700
|
-
**Usage:** The text that is shown when a user has inputted a new item but has not pressed the enter key. To access the current input value, pass a function with a `value` argument (see the [default config](https://github.com/
|
|
730
|
+
**Usage:** The text that is shown when a user has inputted a new item but has not pressed the enter key. To access the current input value, pass a function with a `value` argument (see the [default config](https://github.com/Choices-js/Choices#setup) for an example), otherwise pass a string.
|
|
701
731
|
|
|
702
732
|
Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
|
|
703
733
|
|
|
704
734
|
### removeItemIconText
|
|
705
735
|
|
|
706
|
-
**Type:** `String/Function` **Default:** `Remove item"`
|
|
736
|
+
**Type:** `String/Function` **Default:** `Remove item"` **Arguments:** `value`, `valueRaw`, `item`
|
|
707
737
|
|
|
708
738
|
**Input types affected:** `text`, `select-one`, `select-multiple`
|
|
709
739
|
|
|
710
|
-
**Usage:** The text/icon for the remove button. To access the item's value, pass a function with a `value` argument (see the **default config** [https://github.com/
|
|
740
|
+
**Usage:** The text/icon for the remove button. To access the item's value, pass a function with a `value` argument (see the **default config** [https://github.com/Choices-js/Choices#setup] for an example), otherwise pass a string.
|
|
741
|
+
To access the item's label, use the 3rd argument. *Note*; this label is not escaped.
|
|
711
742
|
|
|
712
743
|
Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
|
|
713
744
|
|
|
714
745
|
### removeItemLabelText
|
|
715
746
|
|
|
716
|
-
**Type:** `String/Function` **Default:** `Remove item: ${value}"`
|
|
747
|
+
**Type:** `String/Function` **Default:** `Remove item: ${value}"` **Arguments:** `value`, `valueRaw`, `item`
|
|
717
748
|
|
|
718
749
|
**Input types affected:** `text`, `select-one`, `select-multiple`
|
|
719
750
|
|
|
720
|
-
**Usage:** The text for the remove button's aria label. To access the item's value, pass a function with a `value` argument (see the **default config** [https://github.com/
|
|
751
|
+
**Usage:** The text for the remove button's aria label. To access the item's value, pass a function with a `value` argument (see the **default config** [https://github.com/Choices-js/Choices#setup] for an example), otherwise pass a string.
|
|
752
|
+
To access the item's label, use the 3rd argument. *Note*; this label is not escaped.
|
|
721
753
|
|
|
722
754
|
Return type must be safe to insert into HTML (ie use the 1st argument which is sanitised)
|
|
723
755
|
|
|
724
756
|
### maxItemText
|
|
725
757
|
|
|
726
|
-
**Type:** `String/Function` **Default:** `Only ${maxItemCount} values can be added`
|
|
758
|
+
**Type:** `String/Function` **Default:** `Only ${maxItemCount} values can be added` **Arguments:** `maxItemCount`
|
|
727
759
|
|
|
728
760
|
**Input types affected:** `text`
|
|
729
761
|
|
|
730
|
-
**Usage:** The text that is shown when a user has focus on the input but has already reached the [max item count](https://github.com/
|
|
762
|
+
**Usage:** The text that is shown when a user has focus on the input but has already reached the [max item count](https://github.com/Choices-js/Choices#maxitemcount). To access the max item count, pass a function with a `maxItemCount` argument (see the [default config](https://github.com/Choices-js/Choices#setup) for an example), otherwise pass a string.
|
|
731
763
|
|
|
732
764
|
### valueComparer
|
|
733
765
|
|
|
734
|
-
**Type:** `Function` **Default:** `strict equality`
|
|
766
|
+
**Type:** `Function` **Default:** `strict equality` **Arguments:** `value1`, `value2`
|
|
735
767
|
|
|
736
768
|
**Input types affected:** `select-one`, `select-multiple`
|
|
737
769
|
|
|
@@ -742,7 +774,7 @@ Return type must be safe to insert into HTML (ie use the 1st argument which is s
|
|
|
742
774
|
```js
|
|
743
775
|
const example = new Choices(element, {
|
|
744
776
|
valueComparer: (a, b) => value.trim() === b.trim(),
|
|
745
|
-
};
|
|
777
|
+
});
|
|
746
778
|
```
|
|
747
779
|
|
|
748
780
|
### labelId
|
|
@@ -784,6 +816,7 @@ classNames: {
|
|
|
784
816
|
selectedState: ['is-selected'],
|
|
785
817
|
flippedState: ['is-flipped'],
|
|
786
818
|
loadingState: ['is-loading'],
|
|
819
|
+
invalidState: ['is-invalid'],
|
|
787
820
|
notice: ['choices__notice'],
|
|
788
821
|
addChoice: ['choices__item--selectable', 'add-choice'],
|
|
789
822
|
noResults: ['has-no-results'],
|
|
@@ -809,11 +842,11 @@ classNames: {
|
|
|
809
842
|
|
|
810
843
|
### callbackOnCreateTemplates(strToEl: (str: string) => HTMLElement, escapeForTemplate: (allowHTML: boolean, s: StringUntrusted | StringPreEscaped | string) => string, getClassNames: (s: Array<string> | string) => string)
|
|
811
844
|
|
|
812
|
-
**Type:** `Function` **Default:** `null` **Arguments:** `strToEl`, `escapeForTemplate`
|
|
845
|
+
**Type:** `Function` **Default:** `null` **Arguments:** `strToEl`, `escapeForTemplate`, `getClassNames`
|
|
813
846
|
|
|
814
847
|
**Input types affected:** `text`, `select-one`, `select-multiple`
|
|
815
848
|
|
|
816
|
-
**Usage:** Function to run on template creation. Through this callback it is possible to provide custom templates for the various components of Choices (see terminology). For Choices to work with custom templates, it is important you maintain the various data attributes defined [here](https://github.com/Choices-js/Choices/blob/
|
|
849
|
+
**Usage:** Function to run on template creation. Through this callback it is possible to provide custom templates for the various components of Choices (see terminology). For Choices to work with custom templates, it is important you maintain the various data attributes defined [here](https://github.com/Choices-js/Choices/blob/main/src/scripts/templates.ts).
|
|
817
850
|
If you want just extend a little original template then you may use `Choices.defaults.templates` to get access to
|
|
818
851
|
original template function.
|
|
819
852
|
|
|
@@ -837,36 +870,39 @@ const example = new Choices(element, {
|
|
|
837
870
|
or more complex:
|
|
838
871
|
|
|
839
872
|
```js
|
|
873
|
+
// StrToEl = (str: string) => HTMLElement | HTMLInputElement | HTMLOptionElement;
|
|
874
|
+
// EscapeForTemplateFn = (allowHTML: boolean, s: StringUntrusted | StringPreEscaped | string) => string;
|
|
875
|
+
// GetClassNamesFn = (s: string | Array<string>) => string;
|
|
840
876
|
const example = new Choices(element, {
|
|
841
|
-
callbackOnCreateTemplates: function(strToEl
|
|
877
|
+
callbackOnCreateTemplates: function(strToEl /*:StrToEl*/, escapeForTemplate /*:EscapeForTemplateFn*/, getClassNames /*:GetClassNamesFn*/) {
|
|
842
878
|
return {
|
|
843
879
|
item: ({ classNames }, data) => {
|
|
844
|
-
return
|
|
880
|
+
return strToEl(`
|
|
845
881
|
<div class="${getClassNames(classNames.item).join(' ')} ${
|
|
846
882
|
getClassNames(data.highlighted
|
|
847
883
|
? classNames.highlightedState
|
|
848
884
|
: classNames.itemSelectable).join(' ')
|
|
849
885
|
} ${
|
|
850
886
|
data.placeholder ? classNames.placeholder : ''
|
|
851
|
-
}" data-item data-id="${data.id}" data-value="${escapeForTemplate(data.value)}" ${
|
|
887
|
+
}" data-item data-id="${data.id}" data-value="${escapeForTemplate(true, data.value)}" ${
|
|
852
888
|
data.active ? 'aria-selected="true"' : ''
|
|
853
889
|
} ${data.disabled ? 'aria-disabled="true"' : ''}>
|
|
854
|
-
<span>★</span> ${escapeForTemplate(data.label)}
|
|
890
|
+
<span>★</span> ${escapeForTemplate(true, data.label)}
|
|
855
891
|
</div>
|
|
856
892
|
`);
|
|
857
893
|
},
|
|
858
894
|
choice: ({ classNames }, data) => {
|
|
859
|
-
return
|
|
895
|
+
return strToEl(`
|
|
860
896
|
<div class="${getClassNames(classNames.item).join(' ')} ${getClassNames(classNames.itemChoice).join(' ')} ${
|
|
861
897
|
getClassNames(data.disabled ? classNames.itemDisabled : classNames.itemSelectable).join(' ')
|
|
862
898
|
}" data-select-text="${this.config.itemSelectText}" data-choice ${
|
|
863
899
|
data.disabled
|
|
864
900
|
? 'data-choice-disabled aria-disabled="true"'
|
|
865
901
|
: 'data-choice-selectable'
|
|
866
|
-
} data-id="${data.id}" data-value="${escapeForTemplate(data.value)}" ${
|
|
902
|
+
} data-id="${data.id}" data-value="${escapeForTemplate(true, data.value)}" ${
|
|
867
903
|
data.groupId > 0 ? 'role="treeitem"' : 'role="option"'
|
|
868
904
|
}>
|
|
869
|
-
<span>★</span> ${escapeForTemplate(data.label)}
|
|
905
|
+
<span>★</span> ${escapeForTemplate(true, data.label)}
|
|
870
906
|
</div>
|
|
871
907
|
`);
|
|
872
908
|
},
|
|
@@ -1258,7 +1294,7 @@ example.setChoiceByValue('Two'); // Choice with value of 'Two' has now been sele
|
|
|
1258
1294
|
|
|
1259
1295
|
## Browser compatibility
|
|
1260
1296
|
|
|
1261
|
-
Choices is compiled using [Babel](https://babeljs.io/) targeting browsers [with more than 1% of global usage](https://github.com/
|
|
1297
|
+
Choices is compiled using [Babel](https://babeljs.io/) targeting browsers [with more than 1% of global usage](https://github.com/Choices-js/Choices/blob/main/.browserslistrc) and expecting that features [listed below](https://github.com/Choices-js/Choices/blob/main/.eslintrc.json#L62) are available or polyfilled in browser.
|
|
1262
1298
|
You may see exact list of target browsers by running `npm exec browserslist` within this repository folder.
|
|
1263
1299
|
If you need to support a browser that does not have one of the features listed below,
|
|
1264
1300
|
I suggest including a polyfill from [cdnjs.cloudflare.com/polyfill](https://cdnjs.cloudflare.com/polyfill):
|
|
@@ -1286,6 +1322,80 @@ Element.prototype.dataset
|
|
|
1286
1322
|
Element.prototype.replaceChildren
|
|
1287
1323
|
```
|
|
1288
1324
|
|
|
1325
|
+
## CSS custom properties
|
|
1326
|
+
|
|
1327
|
+
Since version `11.2`, you are able to customize the behavior and CSS of Choices.js using the following
|
|
1328
|
+
[custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_cascading_variables/Using_CSS_custom_properties).
|
|
1329
|
+
|
|
1330
|
+
| Property | Default | Description |
|
|
1331
|
+
|-----------------------------------|-------------------------------------------|-----------------------------------------------------------------------------|
|
|
1332
|
+
| `--choices-darken` | `black` | Darken color used within the color-mix |
|
|
1333
|
+
| `--choices-lighten` | `white` | Ligten color used within the color-mix |
|
|
1334
|
+
| `--choices-bg-color` | `#f9f9f9` | Background color of the choices element |
|
|
1335
|
+
| `--choices-bg-color-disabled` | `#eaeaea` | Background color of a disabled choices element |
|
|
1336
|
+
| `--choices-bg-color-dropdown` | `#fff` | Background color of the dropdown |
|
|
1337
|
+
| `--choices-text-color` | `#333` | Text color of choices |
|
|
1338
|
+
| `--choices-keyline-color` | `#ddd` | Border-colors within choices |
|
|
1339
|
+
| `--choices-primary-color` | `#005F75` | Primary color |
|
|
1340
|
+
| `--choices-disabled-color` | `#eaeaea` | Background color of disabled items |
|
|
1341
|
+
| `--choices-item-disabled-color` | `#fff` | Text color of disabled items |
|
|
1342
|
+
| `--choices-invalid-color` | `#d33141` | Border color of the invalid state |
|
|
1343
|
+
| `--choices-highlighted-color` | `#f2f2f2` | Highlight background of the choices items |
|
|
1344
|
+
| `--choices-highlight-color` | `#005F75` | Focus color of the choices button |
|
|
1345
|
+
| `--choices-font-size-lg` | `16px` | Basic font size for choices |
|
|
1346
|
+
| `--choices-font-size-md` | `14px` | Font size for medium choices items, e.g. the input field |
|
|
1347
|
+
| `--choices-font-size-sm` | `12px` | Font size for the small choices items, e.g. select multiple or explanations |
|
|
1348
|
+
| `--choices-guttering` | `24px` | Margin-Bottom of the choices wrapper |
|
|
1349
|
+
| `--choices-border-radius` | `2.5px` | Border-radius of the choices element |
|
|
1350
|
+
| `--choices-border-radius-item` | `20px` | Border-radius of the choices items |
|
|
1351
|
+
| `--choices-z-index` | `1` | z-index of the active choices dropdown |
|
|
1352
|
+
| `--choices-input-height` | `44px` | Height of the choices inner element |
|
|
1353
|
+
| `--choices-width` | `100%` | Width of the choices inner element |
|
|
1354
|
+
| `--choices-base-border` | `1px solid var( --choices-keyline-color)` | Bottom-border of the choices inner element |
|
|
1355
|
+
| `--choices-multiple-item-margin` | `3.75px` | Margin of the dropdown items (multiple mode) |
|
|
1356
|
+
| `--choices-multiple-item-padding` | `4px 10px` | Padding of the dropdown items (multiple mode) |
|
|
1357
|
+
| `--choices-dropdown-item-padding` | `10px` | Padding of the choices dropdown items |
|
|
1358
|
+
| `--choices-list-single-padding` | `4px 16px 4px 4px` | Padding of the listbox description |
|
|
1359
|
+
| `--choices-input-margin-bottom` | `5px` | Margin-bottom of the choices input (text inputs) |
|
|
1360
|
+
| `--choices-input-padding` | `4px 0 4px 2px` | Padding of the choices input |
|
|
1361
|
+
| `--choices-inner-padding` | `7.5px 7.5px 3.75px` | Padding of the choices inner element |
|
|
1362
|
+
| `--choices-inner-one-padding` | `7.5px` | Padding of the choices inner element (Single select input) |
|
|
1363
|
+
| `--choices-arrow-size` | `5px` | Size of the choices dropdown symbol |
|
|
1364
|
+
| `--choices-arrow-margin-top` | `-2.5px` | Top offset of the dropdown symbol |
|
|
1365
|
+
| `--choices-arrow-margin-top-open` | `-7.5px` | Top offset of the active dropdown symbol |
|
|
1366
|
+
| `--choices-arrow-right` | `11.5px` | Right offset of the dropdown symbol |
|
|
1367
|
+
| `--choices-icon-cross` | `url("...")` | Button image |
|
|
1368
|
+
| `--choices-icon-cross-inverse` | `url("...")` | Button image (inversed color) |
|
|
1369
|
+
| `--choices-button-offset` | `8px` | Button offset |
|
|
1370
|
+
| `--choices-button-dimension` | `8px` | Button background size |
|
|
1371
|
+
| `--choices-button-line-height` | `1` | Button line height |
|
|
1372
|
+
| `--choices-button-border-radius` | `0` | Button border-radius |
|
|
1373
|
+
| `--choices-button-opacity` | `0.75` | Button opacity |
|
|
1374
|
+
| `--choices-button-opacity-hover` | `1` | Button opacity on hover |
|
|
1375
|
+
| `--choices-placeholder-opacity` | `0.5` | Placeholder opacity |
|
|
1376
|
+
|
|
1377
|
+
### Dark mode example
|
|
1378
|
+
|
|
1379
|
+
The current demo page uses the following variables for its dark mode
|
|
1380
|
+
|
|
1381
|
+
```css
|
|
1382
|
+
@media (prefers-color-scheme: dark) {
|
|
1383
|
+
:root {
|
|
1384
|
+
--choices-primary-color: #38daff;
|
|
1385
|
+
--choices-item-color: black;
|
|
1386
|
+
--choices-bg-color: #101010;
|
|
1387
|
+
--choices-bg-color-dropdown: #101010;
|
|
1388
|
+
--choices-keyline-color: #3b3e40;
|
|
1389
|
+
--choices-bg-color-disabled: #181a1b;
|
|
1390
|
+
--choices-item-disabled-color: #eee;
|
|
1391
|
+
--choices-disabled-color: #2d2d2d;
|
|
1392
|
+
--choices-highlighted-color: #16292d;
|
|
1393
|
+
--choices-icon-cross: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjMDAwIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==");
|
|
1394
|
+
--choices-icon-cross-inverse: url("data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjEiIGhlaWdodD0iMjEiIHZpZXdCb3g9IjAgMCAyMSAyMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48ZyBmaWxsPSIjRkZGIiBmaWxsLXJ1bGU9ImV2ZW5vZGQiPjxwYXRoIGQ9Ik0yLjU5Mi4wNDRsMTguMzY0IDE4LjM2NC0yLjU0OCAyLjU0OEwuMDQ0IDIuNTkyeiIvPjxwYXRoIGQ9Ik0wIDE4LjM2NEwxOC4zNjQgMGwyLjU0OCAyLjU0OEwyLjU0OCAyMC45MTJ6Ii8+PC9nPjwvc3ZnPg==");
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
```
|
|
1398
|
+
|
|
1289
1399
|
## Development
|
|
1290
1400
|
|
|
1291
1401
|
To setup a local environment: clone this repo, navigate into its directory in a terminal window and run the following command:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "choices.js",
|
|
3
|
-
"version": "11.1
|
|
3
|
+
"version": "11.2.1",
|
|
4
4
|
"description": "A vanilla JS customisable text input/select box plugin",
|
|
5
5
|
"main": "./public/assets/scripts/choices.js",
|
|
6
6
|
"module": "./public/assets/scripts/choices.mjs",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
},
|
|
72
72
|
"repository": {
|
|
73
73
|
"type": "git",
|
|
74
|
-
"url": "
|
|
74
|
+
"url": "https://github.com/Choices-js/Choices.git"
|
|
75
75
|
},
|
|
76
76
|
"author": "Josh Johnson",
|
|
77
77
|
"license": "MIT",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"src"
|
|
83
83
|
],
|
|
84
84
|
"bugs": {
|
|
85
|
-
"url": "https://github.com/
|
|
85
|
+
"url": "https://github.com/Choices-js/Choices/issues"
|
|
86
86
|
},
|
|
87
|
-
"homepage": "https://github.com/
|
|
87
|
+
"homepage": "https://github.com/Choices-js/Choices#readme",
|
|
88
88
|
"keywords": [
|
|
89
89
|
"customisable",
|
|
90
90
|
"input",
|
|
@@ -101,18 +101,17 @@
|
|
|
101
101
|
"@babel/preset-typescript": "^7.24.7",
|
|
102
102
|
"@playwright/test": "^1.46.0",
|
|
103
103
|
"@rollup/plugin-babel": "^6.0.4",
|
|
104
|
-
"@rollup/plugin-eslint": "^9.0.5",
|
|
105
104
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
106
105
|
"@rollup/plugin-replace": "^5.0.7",
|
|
107
|
-
"@rollup/plugin-terser": "^0.
|
|
106
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
108
107
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
109
108
|
"@types/chai": "^4.3.17",
|
|
110
|
-
"@types/node": "^22.
|
|
109
|
+
"@types/node": "^22.12.0",
|
|
111
110
|
"@types/sinon": "^17.0.3",
|
|
112
111
|
"@types/sinon-chai": "^3.2.12",
|
|
113
|
-
"@vitest/coverage-v8": "^2.
|
|
112
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
114
113
|
"autoprefixer": "^10.4.20",
|
|
115
|
-
"
|
|
114
|
+
"bundlesize2": "^0.0.35",
|
|
116
115
|
"chai": "^5.1.1",
|
|
117
116
|
"cross-process-lock": "^2.1.1",
|
|
118
117
|
"csso-cli": "^4.0.2",
|
|
@@ -125,9 +124,7 @@
|
|
|
125
124
|
"eslint-plugin-prettier": "^5.2.1",
|
|
126
125
|
"eslint-plugin-sort-class-members": "^1.20.0",
|
|
127
126
|
"eslint-plugin-tree-shaking": "^1.12.2",
|
|
128
|
-
"husky": "^9.1.4",
|
|
129
127
|
"jsdom": "^24.1.1",
|
|
130
|
-
"lint-staged": "^15.2.7",
|
|
131
128
|
"nodemon": "^3.1.4",
|
|
132
129
|
"npm-run-all": "^4.1.5",
|
|
133
130
|
"postcss": "^8.4.41",
|
|
@@ -142,9 +139,9 @@
|
|
|
142
139
|
"stylelint-config-standard": "^36.0.1",
|
|
143
140
|
"stylelint-config-standard-scss": "^13.1.0",
|
|
144
141
|
"tslib": "^2.6.3",
|
|
145
|
-
"typescript": "
|
|
142
|
+
"typescript": "5.5.x",
|
|
146
143
|
"typescript-eslint": "^8.0.1",
|
|
147
|
-
"vitest": "^2.
|
|
144
|
+
"vitest": "^3.2.4"
|
|
148
145
|
},
|
|
149
146
|
"dependencies": {
|
|
150
147
|
"fuse.js": "^7.0.0"
|