@intechstudio/grid-uikit 1.20241206.1355 → 1.20241218.1303

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.
@@ -17,12 +17,13 @@ export let postProcessor = (value2) => {
17
17
  return value2;
18
18
  };
19
19
  export let title = "";
20
+ export let searchable = false;
20
21
  const dispatch = createEventDispatcher();
21
22
  let isError = false;
22
- let infoValue = "";
23
23
  let oldValue = void 0;
24
24
  let inputValue;
25
25
  let selected = writable();
26
+ let inputElement;
26
27
  const {
27
28
  elements: { trigger, content, arrow, close },
28
29
  states: { open }
@@ -39,6 +40,12 @@ $:
39
40
  handleSelectionChange($selected);
40
41
  $:
41
42
  handleInputChange(inputValue);
43
+ $:
44
+ filteredSuggestions = searchable ? suggestions.filter(
45
+ (e) => e.info.toLowerCase().includes(inputValue?.toLowerCase()) || e.value.toLowerCase().includes(inputValue?.toLowerCase())
46
+ ) : suggestions;
47
+ $:
48
+ infoValue = suggestions.find((s) => String(s.value).trim() == String(inputValue).trim())?.info || "";
42
49
  function handleValueChange(value2) {
43
50
  if (inputValue === value2 || !value2) {
44
51
  return;
@@ -53,7 +60,6 @@ function handleSelectionChange(option) {
53
60
  handleChange();
54
61
  }
55
62
  function handleInputChange(input) {
56
- infoValue = suggestions.find((s) => String(s.value).trim() == String(input).trim())?.info || "";
57
63
  isError = !validator(input);
58
64
  if (oldValue === void 0) {
59
65
  oldValue = value;
@@ -72,6 +78,12 @@ function handleChange() {
72
78
  dispatch("change", postProcessor(inputValue));
73
79
  }
74
80
  }
81
+ function handleFocus() {
82
+ filteredSuggestions = suggestions;
83
+ if (searchable) {
84
+ inputElement.select();
85
+ }
86
+ }
75
87
  </script>
76
88
 
77
89
 
@@ -84,10 +96,12 @@ function handleChange() {
84
96
  {title}
85
97
 
86
98
  <input
99
+ bind:this={inputElement}
87
100
  type="text"
88
101
  use:melt={$trigger}
89
102
  bind:value={inputValue}
90
103
  on:change={handleChange}
104
+ on:focus={handleFocus}
91
105
  class="trigger w-full flex flex-row border mb-1 {isError && !disabled
92
106
  ? 'border-error'
93
107
  : 'border-black'} p-2 {disabled
@@ -105,7 +119,7 @@ function handleChange() {
105
119
  class="menu"
106
120
  >
107
121
  <div>
108
- {#each suggestions as suggestion}
122
+ {#each filteredSuggestions as suggestion}
109
123
  <option
110
124
  use:melt={$close}
111
125
  class="cursor-pointer truncate hover:bg-white/40 flex w-full px-2 py-1 hover:text-white"
@@ -13,6 +13,7 @@ declare const __propDef: {
13
13
  preProcessor?: (value: string) => string;
14
14
  postProcessor?: (value: string) => string;
15
15
  title?: string;
16
+ searchable?: boolean;
16
17
  };
17
18
  events: {
18
19
  validator: CustomEvent<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intechstudio/grid-uikit",
3
- "version": "1.20241206.1355",
3
+ "version": "1.20241218.1303",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "vite build",