vue3-extended-multiselect 1.1.2 → 1.1.4

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.
package/.eslintrc.js CHANGED
@@ -10,9 +10,9 @@ module.exports = {
10
10
  parserOptions: {
11
11
  parser: "babel-eslint",
12
12
  sourceType: "module",
13
- ecmaVersion: "latest",
13
+ ecmaVersion: "13",
14
14
  ecmaFeatures: {
15
- "modules": true
15
+ modules: true
16
16
  },
17
17
  },
18
18
  rules: {
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Patch notes
2
2
 
3
- Current `vue3-extended-multiselect` version: **1.1.2**
3
+ Current `vue3-extended-multiselect` version: **1.1.4**
4
4
 
5
5
  ***
6
6
 
@@ -84,7 +84,7 @@ Adding descriptive comments for some types in typings.
84
84
  * Adding image-path.js file with "useImagePath" custom hook.
85
85
  * Adding emitter import in composition api from "mitt" dependency.
86
86
  * Adding some new css-variabled.
87
- * Removal of sone old css-variables.
87
+ * Removal of some old css-variables.
88
88
  * Changing styles of "marker" and "option" slots.
89
89
  * Adding new fields in "parserOptions" section of .eslintrc.
90
90
  * Disabling "no-undef" rule in .eslintrc.
@@ -106,4 +106,12 @@ Adding descriptive comments for some types in typings.
106
106
  * Replacing package-lock.json file with new one.
107
107
 
108
108
  ### 1.1.2 (2022-12-10)
109
- * Replacing dev-dependency "@vue/cli-plugin-eslint" with its latest version.
109
+ * Replacing dev-dependency "@vue/cli-plugin-eslint" with its latest version.
110
+
111
+ ### 1.1.3 (2022-12-11)
112
+ * Adding "searchByField" optional prop.
113
+ * Adding unit-test for new optional prop.
114
+
115
+ ### 1.1.4 (2022-13-11)
116
+ * Adding "optionCreateLabel" to expose as utility.
117
+ * Fix bug with wrong name of label field
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # vue3-extended-multiselect v1.1.2
1
+ # vue3-extended-multiselect v1.1.4
2
2
 
3
3
  ***
4
4
 
@@ -67,6 +67,7 @@ Prop name | Prop type | Prop appointment | Prop default value | Prop values
67
67
  **label**|String|Defines field in options of type "object" that will be the label of option.|"label"|—|
68
68
  **loaderIcon<br/>Filter**|String|Defines svg-filter with color settings for loader icon.|"loader-default"|"loader-default", "basic", "slate-grey", "slate-blue", "teal",<br/> "strict"|
69
69
  **placeholder**|String|Placeholder for search field to be used if user is not allowed to create new options.|"Select features"|&mdash;|
70
+ **searchByField**|String|Determines field in options of type "object" to use in internal search.|""|&mdash;|
70
71
  **themeType**|String|Defines overall color theme for extended multiselect.|"basic"|"basic", "slate-grey", "slate-blue", "teal",<br/> "strict"|
71
72
  **toggle<br/>Appearance<br/>Side**|String|Defines which side options list will be displayed on.|"auto"|"auto", "atop", "under"|
72
73
  **toggleIcon**|String|Defines kind of toggle icon from icons collection.|"double-arrow"|"base-arrow", "double-arrow", "wide-arrow", "circle-arrow", "inner-arrow", "triangle-arrow", "triangle-circle-arrow"|
package/jest.config.js CHANGED
@@ -13,6 +13,7 @@ module.exports = {
13
13
  OPTIONS: [
14
14
  { label: "First Option", customLabel: "First Option Custom Label" },
15
15
  { label: "Second Option" },
16
+ { label: "Third Option", searchByField: "First" },
16
17
  126,
17
18
  ],
18
19
  INPUT_ID: "vue3-extended-multiselect-input-1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-extended-multiselect",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Extended multiselect component for applications based on Vue 3 framework",
5
5
  "keywords": [
6
6
  "multiselect",
@@ -38,6 +38,7 @@
38
38
  :loading="loading"
39
39
  :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
40
40
  :empty-objects-placeholder="emptyObjectsPlaceholder"
41
+ :label="label"
41
42
  :multiple-blocks-limit-message="multipleBlocksLimitMessage"
42
43
  :theme-type="themeType"
43
44
  :increase-display-by="increaseDisplayBy"
@@ -75,6 +76,7 @@
75
76
  :loading="loading"
76
77
  :toggle-multiple-blocks-limit="toggleMultipleBlocksLimit"
77
78
  :empty-objects-placeholder="emptyObjectsPlaceholder"
79
+ :label="label"
78
80
  :multiple-blocks-limit-message="multipleBlocksLimitMessage"
79
81
  :theme-type="themeType"
80
82
  :increase-display-by="increaseDisplayBy"
@@ -265,6 +267,15 @@ const props = defineProps({
265
267
  required: true,
266
268
  },
267
269
 
270
+ /**
271
+ * Determines field of option which will be displayed as label
272
+ * @property {string} label
273
+ */
274
+ label: {
275
+ type: String,
276
+ required: true,
277
+ },
278
+
268
279
  /**
269
280
  * "placeholder" attribute for search field
270
281
  * @property {string} placeholder
@@ -92,6 +92,15 @@ const props = defineProps({
92
92
  required: true,
93
93
  },
94
94
 
95
+ /**
96
+ * Determines field of option which will be displayed as label
97
+ * @property {string} label
98
+ */
99
+ label: {
100
+ type: String,
101
+ required: true,
102
+ },
103
+
95
104
  /**
96
105
  * Limit of hidden options amount to be shown next
97
106
  * @property {number} increaseDisplayBy
@@ -161,6 +170,7 @@ const {
161
170
  createCustomOptionLabel,
162
171
  disabled,
163
172
  emptyObjectsPlaceholder,
173
+ label,
164
174
  increaseDisplayBy,
165
175
  loading,
166
176
  multipleBlocksLimit,
@@ -175,7 +185,11 @@ const optionsLimitIncreaser = ref(null);
175
185
  const increaserClass = ref("extended__multiselect-increaser");
176
186
  const deselectImage = ref(createImagePath("cancel.svg"));
177
187
 
178
- const { optionCreateLabel } = useLabels(createCustomOptionLabel, emptyObjectsPlaceholder);
188
+ const { optionCreateLabel } = useLabels(
189
+ label,
190
+ createCustomOptionLabel,
191
+ emptyObjectsPlaceholder,
192
+ );
179
193
 
180
194
  /**
181
195
  * Defines class for every selected option block
@@ -226,6 +226,16 @@ const props = defineProps({
226
226
  required: true,
227
227
  },
228
228
 
229
+ /**
230
+ * Determines field in options of type "object"
231
+ * to use in internal search.
232
+ * @property {string} searchByField
233
+ */
234
+ searchByField: {
235
+ type: String,
236
+ required: true,
237
+ },
238
+
229
239
  /**
230
240
  * Current theme of extended-multiselect
231
241
  * used in class definition
@@ -406,6 +416,7 @@ const {
406
416
  emptyObjectsPlaceholder,
407
417
  highlightOptions,
408
418
  label,
419
+ searchByField,
409
420
  maxOptionsCount,
410
421
  minOptionsCount,
411
422
  multiple,
@@ -427,7 +438,11 @@ const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
427
438
  emptyObjectsPlaceholder,
428
439
  showInsertWarnings,
429
440
  );
430
- const { optionCreateLabel } = useLabels(createCustomOptionLabel, emptyObjectsPlaceholder);
441
+ const { optionCreateLabel } = useLabels(
442
+ label,
443
+ createCustomOptionLabel,
444
+ emptyObjectsPlaceholder,
445
+ );
431
446
 
432
447
  /**
433
448
  * List of options filtered by "disabled" and "selected" signs
@@ -753,7 +768,18 @@ const filterBySearchPattern = (optionsList) => {
753
768
  if (Array.isArray(option)) {
754
769
  return searchState.searchPattern.test(option.length ? option.join(", ") : emptyObjectsPlaceholder.value);
755
770
  }
756
- return searchState.searchPattern.test(option[label.value].toString());
771
+
772
+ let internalSearchResult;
773
+
774
+ if (searchByField.value.length) {
775
+ if (!option[searchByField.value]) return false;
776
+
777
+ internalSearchResult = option[searchByField.value].toString();
778
+ } else {
779
+ internalSearchResult = option[label.value].toString();
780
+ }
781
+
782
+ return searchState.searchPattern.test(internalSearchResult);
757
783
  } else {
758
784
  return searchState.searchPattern.test(option.toString());
759
785
  }
@@ -1054,8 +1080,8 @@ onBeforeMount(() => {
1054
1080
  emitter.on("extended:select-enter", (keyboardEvent) => {
1055
1081
  if (!enterIndex.value) return;
1056
1082
 
1057
- const option = this.availableOptions[this.enterIndex];
1058
- this.selectOption(option, keyboardEvent);
1083
+ const option = availableOptions.value[enterIndex.value];
1084
+ selectOption(option, keyboardEvent);
1059
1085
  });
1060
1086
 
1061
1087
  emitter.on("extended:reset-index", () => {
@@ -39,6 +39,7 @@
39
39
  :placeholder="placeholder"
40
40
  :show-search-field="showSearchField"
41
41
  :empty-objects-placeholder="emptyObjectsPlaceholder"
42
+ :label="label"
42
43
  :multiple-blocks-limit-message="multipleBlocksLimitMessage"
43
44
  :theme-type="themeType"
44
45
  :increase-display-by="increaseDisplayBy"
@@ -136,6 +137,7 @@
136
137
  :create-option-type="createOptionType"
137
138
  :empty-objects-placeholder="emptyObjectsPlaceholder"
138
139
  :label="label"
140
+ :search-by-field="searchByField"
139
141
  :theme-type="themeType"
140
142
  :any-option-wrapper-block-height="anyOptionWrapperBlockHeight"
141
143
  :max-options-count="maxOptionsCount"
@@ -205,6 +207,7 @@
205
207
  import {
206
208
  computed,
207
209
  defineEmits,
210
+ defineExpose,
208
211
  defineProps,
209
212
  onBeforeMount,
210
213
  onMounted,
@@ -233,6 +236,7 @@ import {
233
236
 
234
237
  import useToggle from "../composition/toggle";
235
238
  import useCancel from "../composition/cancel";
239
+ import useLabels from "../composition/labels";
236
240
  import usePreselectedOptions from "../composition/preselected-options";
237
241
  import useSearchValue from "../composition/search-value";
238
242
 
@@ -571,6 +575,17 @@ const props = defineProps({
571
575
  default: "Select features",
572
576
  },
573
577
 
578
+ /**
579
+ * Determines field in options of type "object"
580
+ * to use in internal search.
581
+ * @default ""
582
+ * @property {string} searchByField
583
+ */
584
+ searchByField: {
585
+ type: String,
586
+ default: "",
587
+ },
588
+
574
589
  /**
575
590
  * Defines overall color theme for extended multiselect
576
591
  * @default "basic"
@@ -880,6 +895,7 @@ const {
880
895
  toggleMaxHeight,
881
896
  toggleOptionsBySelect,
882
897
  wrongCurrentValue,
898
+ createCustomOptionLabel,
883
899
  } = toRefs(props);
884
900
 
885
901
  const {
@@ -908,6 +924,11 @@ const { createLabel, optionTypeRestrictor } = usePreselectedOptions(
908
924
  emptyObjectsPlaceholder,
909
925
  showInsertWarnings,
910
926
  );
927
+ const { optionCreateLabel } = useLabels(
928
+ label,
929
+ createCustomOptionLabel,
930
+ emptyObjectsPlaceholder,
931
+ );
911
932
  const attrs = useAttrs();
912
933
  const slots = useSlots();
913
934
 
@@ -1657,6 +1678,10 @@ onMounted(() => {
1657
1678
  dropdownActive.value = true;
1658
1679
  });
1659
1680
  });
1681
+
1682
+ defineExpose({
1683
+ optionCreateLabel,
1684
+ });
1660
1685
  </script>
1661
1686
 
1662
1687
  <style>
@@ -1,10 +1,12 @@
1
1
  export default function useLabels(
2
+ label,
2
3
  createCustomOptionLabel,
3
4
  emptyObjectsPlaceholder,
4
5
  ) {
5
6
  /**
6
7
  * Creates label of any kind of option
7
8
  * @function
9
+ * @param {string} label - label field in options of type "object"
8
10
  * @param {option} UnionPropType
9
11
  * @returns {string} label
10
12
  */
@@ -27,10 +29,10 @@ export default function useLabels(
27
29
  return emptyObjectsPlaceholder.value;
28
30
  }
29
31
 
30
- const hasLabel = Object.getOwnPropertyNames(option).includes("label");
32
+ const hasLabel = Object.getOwnPropertyNames(option).includes(label.value);
31
33
 
32
34
  if (hasLabel) {
33
- return typeof option.label === "object" ? JSON.stringify(option.label) : option.label;
35
+ return typeof option[label.value] === "object" ? JSON.stringify(option[label.value]) : option[label.value];
34
36
  }
35
37
 
36
38
  return "";
@@ -6,6 +6,7 @@ export default function usePreselectedOptions(
6
6
  /**
7
7
  * Creates string label for any kind of option
8
8
  * @function
9
+ * @param {string} label - label field in options of type "object"
9
10
  * @param {boolean} isObjectOrArray - determines whether option is of type "object" or instance of Array
10
11
  * @param {UnionPropType} option - option which needs label
11
12
  * @returns {string} label
@@ -272,7 +272,7 @@ describe("props", () => {
272
272
  const optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
273
273
  const optionsListWrapper = optionsWrapper.find(".extended__multiselect-options_container");
274
274
 
275
- expect(optionsListWrapper.element.children).toHaveLength(3);
275
+ expect(optionsListWrapper.element.children).toHaveLength(4);
276
276
  });
277
277
 
278
278
 
@@ -582,6 +582,28 @@ describe("props", () => {
582
582
  });
583
583
 
584
584
 
585
+ it("correctly handles 'searchByField' prop value", async () => {
586
+ const propsData = {
587
+ options: globalThis.OPTIONS,
588
+ searchByField: "searchByField",
589
+ };
590
+
591
+ wrapper = await mountComponent(
592
+ Vue3ExtendedMultiselect,
593
+ false,
594
+ propsData,
595
+ wrapperProvides(globalThis.SEARCH_VALUE_WITH_RESULTS, SEARCH_PATTERN),
596
+ );
597
+
598
+ await expandOptionsList(wrapper);
599
+
600
+ const optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
601
+ const optionsListWrapper = optionsWrapper.find(".extended__multiselect-options_container");
602
+
603
+ expect(optionsListWrapper.element.children).toHaveLength(1);
604
+ });
605
+
606
+
585
607
  it("correctly handles 'themeType' prop value", async () => {
586
608
  expect.assertions(3);
587
609
 
@@ -595,6 +617,8 @@ describe("props", () => {
595
617
 
596
618
  wrapper = await mountComponent(Vue3ExtendedMultiselect, false, propsData);
597
619
 
620
+ await expandOptionsList(wrapper);
621
+
598
622
  const multiselectWrapper = wrapper.find("#extended__multiselect");
599
623
  const multipleWrapper = wrapper.findComponent(ExtendedMultiselectMultiple);
600
624
  const optionWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
@@ -833,7 +857,7 @@ describe("props", () => {
833
857
 
834
858
  const optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
835
859
  const optionsListWrapper = optionsWrapper.find(".extended__multiselect-options_container");
836
- const optionElement = optionsListWrapper.findAll(".extended__multiselect-options_option").at(2);
860
+ const optionElement = optionsListWrapper.findAll(".extended__multiselect-options_option").at(3);
837
861
 
838
862
  expect(optionElement.classes()).toContain("extended__multiselect-options_option--disabled");
839
863
  });
@@ -852,7 +876,7 @@ describe("props", () => {
852
876
  let optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
853
877
  let optionsListWrapper = optionsWrapper.find(".extended__multiselect-options_container");
854
878
 
855
- expect(optionsListWrapper.element.children).toHaveLength(3);
879
+ expect(optionsListWrapper.element.children).toHaveLength(4);
856
880
 
857
881
  const optionsLoader = async () => {
858
882
  return await Promise.resolve(globalThis.OPTIONS);
@@ -863,7 +887,7 @@ describe("props", () => {
863
887
  wrapper = await mountComponent(Vue3ExtendedMultiselect, false, propsData);
864
888
 
865
889
  process.nextTick(async () => {
866
- expect(wrapper.vm.rawOptions).toHaveLength(3);
890
+ expect(wrapper.vm.rawOptions).toHaveLength(4);
867
891
  done();
868
892
  });
869
893
  });
@@ -1032,7 +1056,7 @@ describe("props", () => {
1032
1056
  const inputWrapper = wrapper.findComponent(ExtendedMultiselectInput);
1033
1057
  const selectedOption = inputWrapper.find(".extended__multiselect-block").find("span");
1034
1058
 
1035
- expect(optionsListWrapper.element.children).toHaveLength(2);
1059
+ expect(optionsListWrapper.element.children).toHaveLength(3);
1036
1060
  expect(selectedOption.text()).toEqual(globalThis.OPTIONS[0].label);
1037
1061
 
1038
1062
  done();
@@ -10,6 +10,7 @@ export type Cancel = () => void;
10
10
  export type CreateCustomOptionLabel = (option: UnionOptionType) => null | string;
11
11
  export type Increase = Cancel;
12
12
  export type DeselectBlock = (index: number) => void;
13
+ export type OptionCreateLabel = CreateCustomOptionLabel;
13
14
  export type ToggleOptionsList = (keyboardEvent?: KeyboardEvent) => void;
14
15
 
15
16
  interface InputIdInPayload {