@dataloop-ai/components 0.20.261-new-input.1 → 0.20.261-new-input.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dataloop-ai/components",
3
- "version": "0.20.261-new-input.1",
3
+ "version": "0.20.261-new-input.3",
4
4
  "exports": {
5
5
  ".": "./index.ts",
6
6
  "./models": "./models.ts",
@@ -160,14 +160,15 @@
160
160
  </div>
161
161
  <dl-menu
162
162
  v-if="showSuggestItems"
163
- v-model="isMenuOpen"
164
- auto-close
163
+ :model-value="isMenuOpen"
164
+ persistent
165
165
  no-focus
166
+ no-refocus
166
167
  :offset="[0, 3]"
167
168
  fit-container
168
169
  :fit-content="fitContent"
169
170
  :arrow-nav-items="stringSuggestions"
170
- @click="onMenuShow"
171
+ @update:model-value="onSuggestionMenuModelUpdate"
171
172
  @highlighted-item="setHighlightedIndex"
172
173
  @selected-item="handleSelectedItem"
173
174
  >
@@ -176,7 +177,10 @@
176
177
  :style="{ maxWidth: suggestMenuWidth }"
177
178
  >
178
179
  <slot name="suggestion-header">
179
- <dl-list-item v-if="suggestionHeader">
180
+ <dl-list-item
181
+ v-if="suggestionHeader"
182
+ class="dl-input__suggestion--header"
183
+ >
180
184
  {{ suggestionHeader }}
181
185
  </dl-list-item>
182
186
  </slot>
@@ -193,6 +197,7 @@
193
197
  :highlighted="
194
198
  suggestIndex === highlightedIndex
195
199
  "
200
+ @mousedown.prevent
196
201
  @click="onClick($event, item)"
197
202
  >
198
203
  <slot
@@ -742,7 +747,10 @@ export default defineComponent({
742
747
  const setHighlightedIndex = (value: any) => {
743
748
  highlightedIndex.value = value
744
749
  }
745
- const handleSelectedItem = (value: any) => {
750
+ const handleSelectedItem = (value: unknown) => {
751
+ if (typeof value !== 'string') {
752
+ return
753
+ }
746
754
  onAutoSuggestClick(null, value)
747
755
  }
748
756
 
@@ -834,7 +842,11 @@ export default defineComponent({
834
842
  }
835
843
 
836
844
  const onAutoSuggestClick = (e: Event, item: string): void => {
837
- const newValue = clearSuggestion(modelValue.value.toString(), item)
845
+ if (typeof item !== 'string' || !item.trim().length) {
846
+ return
847
+ }
848
+ const currentValue = String(modelValue.value ?? '')
849
+ const newValue = clearSuggestion(currentValue, item)
838
850
  if (!maxLength.value || newValue.length < maxLength.value) {
839
851
  const toEmit = newValue.replace(new RegExp('&nbsp;', 'g'), ' ')
840
852
  emit('input', toEmit, e)
@@ -843,6 +855,7 @@ export default defineComponent({
843
855
  setCaretAtTheEnd(input.value)
844
856
  isInternalChange.value = true
845
857
  }
858
+ isMenuOpen.value = false
846
859
  }
847
860
 
848
861
  const emitAddFile = (file: DlInputFile) => {
@@ -1345,6 +1358,14 @@ export default defineComponent({
1345
1358
  const inputRef = this.$refs.input as HTMLInputElement
1346
1359
  inputRef.blur()
1347
1360
  },
1361
+ closeSuggestionMenuAfterBlur(): void {
1362
+ // Delay close so suggestion item click can finish before menu teardown.
1363
+ setTimeout(() => {
1364
+ if (!this.focused) {
1365
+ this.isMenuOpen = false
1366
+ }
1367
+ }, 0)
1368
+ },
1348
1369
  onBlur(e: InputEvent): void {
1349
1370
  const el = e.target as HTMLElement
1350
1371
  el.innerText = (el.innerText ?? '').endsWith('.')
@@ -1352,7 +1373,7 @@ export default defineComponent({
1352
1373
  : el.innerText
1353
1374
  el.scroll(0, 0)
1354
1375
  this.focused = false
1355
- this.isMenuOpen = false
1376
+ this.closeSuggestionMenuAfterBlur()
1356
1377
  this.$emit('blur', e)
1357
1378
  this.handleValueTrim()
1358
1379
  },
@@ -1369,7 +1390,7 @@ export default defineComponent({
1369
1390
  },
1370
1391
  onNativeBlur(e: FocusEvent): void {
1371
1392
  this.focused = false
1372
- this.isMenuOpen = false
1393
+ this.closeSuggestionMenuAfterBlur()
1373
1394
  this.$emit('blur', e)
1374
1395
  },
1375
1396
  onNativeEnterPress(e: KeyboardEvent): void {
@@ -1396,8 +1417,12 @@ export default defineComponent({
1396
1417
  onPassShowClick(): void {
1397
1418
  this.showPass = !this.showPass
1398
1419
  },
1399
- onMenuShow(): void {
1400
- this.focus()
1420
+ onSuggestionMenuModelUpdate(value: boolean): void {
1421
+ if (!value && this.focused && this.openSuggestionsOnFocus) {
1422
+ this.openSuggestionMenuOnFocus()
1423
+ return
1424
+ }
1425
+ this.isMenuOpen = value
1401
1426
  },
1402
1427
  getSuggestWords(
1403
1428
  item: string,
@@ -1747,6 +1772,13 @@ export default defineComponent({
1747
1772
  }
1748
1773
 
1749
1774
  &__suggestion {
1775
+ &--header {
1776
+ font-family: var(--dl-typography-body-body3-font-family);
1777
+ font-size: var(--dl-typography-body-body3-font-size);
1778
+ line-height: var(--dl-typography-body-body3-line-height);
1779
+ font-weight: var(--dl-typography-body-body3-font-weight);
1780
+ color: var(--dell-gray-600);
1781
+ }
1750
1782
  &--highlighted {
1751
1783
  background-color: var(--dl-color-warning);
1752
1784
  border-radius: 2px;
@@ -16,7 +16,8 @@ export function addEventListenersToElement(
16
16
  }
17
17
 
18
18
  export function clearSuggestion(text: string, suggestion: string) {
19
- return text.split(' ').slice(0, -1).join(' ') + ' ' + suggestion
19
+ const prefix = text.split(' ').slice(0, -1).join(' ')
20
+ return prefix ? `${prefix} ${suggestion}` : suggestion
20
21
  }
21
22
 
22
23
  export function setInnerHTMLWithCursor(
@@ -124,6 +124,15 @@
124
124
  />
125
125
  </template>
126
126
  </dl-input>
127
+ <dl-input
128
+ v-model="headerSuggestionsValue"
129
+ style="width: 320px"
130
+ title="Suggestions with header and icons"
131
+ placeholder="Type to see suggestions"
132
+ suggestion-header="Suggested users"
133
+ :auto-suggest-items="headerSuggestionsItems"
134
+ open-suggestions-on-focus
135
+ />
127
136
  <div class="numberClip" style="max-width: 64px">
128
137
  <dl-input
129
138
  v-model="numberClip"
@@ -249,7 +258,10 @@
249
258
  import { v4 } from 'uuid'
250
259
  import { computed, defineComponent, ref } from 'vue-demi'
251
260
  import { DlInput, DlButton, DlIcon, DlSwitch } from '../components'
252
- import { DlInputFile } from '../components/compound/DlInput/types'
261
+ import {
262
+ DlInputFile,
263
+ DlInputSuggestion
264
+ } from '../components/compound/DlInput/types'
253
265
  export default defineComponent({
254
266
  name: 'DlInputDemo',
255
267
  components: {
@@ -265,6 +277,21 @@ export default defineComponent({
265
277
  const sizeSFieldValue = ref<string>('')
266
278
  const errorFieldValue = ref<string>('')
267
279
  const saveInputValue = ref<string>('Test vaaalueeee')
280
+ const headerSuggestionsValue = ref<string>('')
281
+ const headerSuggestionsItems = ref<DlInputSuggestion[]>([
282
+ {
283
+ suggestion: '@john-doe',
284
+ startIcon: 'icon-dl-user'
285
+ },
286
+ {
287
+ suggestion: '@jane-smith',
288
+ startIcon: 'icon-dl-user'
289
+ },
290
+ {
291
+ suggestion: '@team-design',
292
+ startIcon: 'icon-dl-users'
293
+ }
294
+ ])
268
295
 
269
296
  const files = ref<DlInputFile[]>([])
270
297
  const addFile = (e: Event) => {
@@ -313,6 +340,8 @@ export default defineComponent({
313
340
  warningFieldValue,
314
341
  errorFieldValue,
315
342
  saveInputValue,
343
+ headerSuggestionsValue,
344
+ headerSuggestionsItems,
316
345
  sizeSFieldValue,
317
346
  files,
318
347
  updateFiles,