@symfony/ux-autocomplete 2.34.0 → 2.36.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.
@@ -19,6 +19,7 @@ declare class export_default extends Controller {
19
19
  minCharacters: NumberConstructor;
20
20
  tomSelectOptions: ObjectConstructor;
21
21
  preload: StringConstructor;
22
+ resetOnFocus: BooleanConstructor;
22
23
  };
23
24
  readonly urlValue: string;
24
25
  readonly optionsAsHtmlValue: boolean;
@@ -31,6 +32,7 @@ declare class export_default extends Controller {
31
32
  readonly tomSelectOptionsValue: object;
32
33
  readonly hasPreloadValue: boolean;
33
34
  readonly preloadValue: string;
35
+ readonly resetOnFocusValue: boolean;
34
36
  tomSelect: TomSelect | undefined;
35
37
  private mutationObserver;
36
38
  private isObserving;
@@ -275,8 +275,8 @@ function _createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacter
275
275
  optgroupField: "group_by",
276
276
  score: (_search) => (_item) => 1,
277
277
  render: {
278
- option: (item) => `<div>${item[labelField]}</div>`,
279
- item: (item) => `<div>${item[labelField]}</div>`,
278
+ option: (item, escape) => `<div>${this.optionsAsHtmlValue ? item[labelField] : escape(item[labelField])}</div>`,
279
+ item: (item, escape) => `<div>${this.optionsAsHtmlValue ? item[labelField] : escape(item[labelField])}</div>`,
280
280
  loading_more: () => {
281
281
  return `<div class="loading-more-results">${this.loadingMoreTextValue}</div>`;
282
282
  },
@@ -290,6 +290,16 @@ function _createAutocompleteWithRemoteData(autocompleteEndpointUrl, minCharacter
290
290
  return `<div class="create">${this.createOptionTextValue.replace("%placeholder%", `<strong>${escapeData(data.input)}</strong>`)}</div>`;
291
291
  }
292
292
  },
293
+ onFocus: () => {
294
+ if (this.resetOnFocusValue && this.tomSelect) {
295
+ if (this.tomSelect.control_input.value.trim() === "") {
296
+ this.tomSelect.clearOptions();
297
+ this.tomSelect.loadedSearches = {};
298
+ if (typeof this.tomSelect["clearPagination"] === "function") this.tomSelect["clearPagination"]();
299
+ this.tomSelect.load("");
300
+ }
301
+ }
302
+ },
293
303
  preload: this.preload
294
304
  });
295
305
  return _assertClassBrand(_Class_brand, this, _createTomSelect).call(this, config);
@@ -333,6 +343,7 @@ _Class.values = {
333
343
  createOptionText: String,
334
344
  minCharacters: Number,
335
345
  tomSelectOptions: Object,
336
- preload: String
346
+ preload: String,
347
+ resetOnFocus: Boolean
337
348
  };
338
349
  export { _Class as default };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@symfony/ux-autocomplete",
3
3
  "description": "JavaScript Autocomplete functionality for Symfony",
4
4
  "license": "MIT",
5
- "version": "2.34.0",
5
+ "version": "2.36.0",
6
6
  "keywords": [
7
7
  "symfony-ux"
8
8
  ],