@dataloop-ai/components 0.17.91 → 0.17.93
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 +1 -1
- package/src/components/compound/DlSearches/DlSmartSearch/components/DlSmartSearchInput.vue +10 -2
- package/src/demos/DlDropdownButtonDemo.vue +0 -1
- package/src/demos/DlMenuDemo.vue +4 -2
- package/src/demos/DlTooltipDemo.vue +2 -0
- package/src/hooks/use-arrow-navigation.ts +64 -21
- package/src/hooks/use-portal.ts +1 -5
package/package.json
CHANGED
|
@@ -394,10 +394,18 @@ export default defineComponent({
|
|
|
394
394
|
modelValue(value: string) {
|
|
395
395
|
const target = this.$refs['input'] as HTMLInputElement
|
|
396
396
|
value = value?.replaceAll(' ', ' ') ?? ''
|
|
397
|
-
|
|
397
|
+
/*
|
|
398
|
+
* I commented out this line because it was blocking arrow navigation
|
|
399
|
+
* */
|
|
400
|
+
// if (!this.isTyping) target.innerHTML = value
|
|
401
|
+
target.innerHTML = value
|
|
398
402
|
updateEditor(this.styleModel)
|
|
399
403
|
this.setMenuOffset(isEligibleToChange(target, this.expanded))
|
|
400
|
-
|
|
404
|
+
/*
|
|
405
|
+
* I commented out this line because it was blocking arrow navigation
|
|
406
|
+
* */
|
|
407
|
+
// if (!this.isTyping) setCaret(target)
|
|
408
|
+
setCaret(target)
|
|
401
409
|
if (!this.expanded) {
|
|
402
410
|
this.isOverflow =
|
|
403
411
|
isEllipsisActive(this.$refs['input'] as Element) ||
|
package/src/demos/DlMenuDemo.vue
CHANGED
|
@@ -524,6 +524,8 @@ import {
|
|
|
524
524
|
import { defineComponent, onMounted, ref, watch } from 'vue-demi'
|
|
525
525
|
import { useArrowNavigation } from '../hooks/use-arrow-navigation'
|
|
526
526
|
|
|
527
|
+
type ItemType = Record<string, any> | string
|
|
528
|
+
|
|
527
529
|
export default defineComponent({
|
|
528
530
|
name: 'DlMenuDemo',
|
|
529
531
|
components: {
|
|
@@ -537,7 +539,7 @@ export default defineComponent({
|
|
|
537
539
|
setup() {
|
|
538
540
|
const showing = ref(false)
|
|
539
541
|
const isMenuOpen = ref(false)
|
|
540
|
-
const arrowNavigationLabel = ref('Arrow Navigation Label')
|
|
542
|
+
const arrowNavigationLabel = ref<ItemType>('Arrow Navigation Label')
|
|
541
543
|
|
|
542
544
|
const listItems = ref([
|
|
543
545
|
'New tab',
|
|
@@ -560,7 +562,7 @@ export default defineComponent({
|
|
|
560
562
|
isMenuOpen
|
|
561
563
|
)
|
|
562
564
|
|
|
563
|
-
watch(selectedItem, (value: string) => {
|
|
565
|
+
watch(selectedItem, (value: ItemType | string) => {
|
|
564
566
|
arrowNavigationLabel.value = value
|
|
565
567
|
})
|
|
566
568
|
|
|
@@ -1,41 +1,84 @@
|
|
|
1
|
-
import { ref, onMounted, onBeforeUnmount } from 'vue-demi'
|
|
1
|
+
import { ref, isRef, onMounted, onBeforeUnmount, computed } from 'vue-demi'
|
|
2
|
+
|
|
3
|
+
type ItemType = Record<string, any> | string
|
|
2
4
|
|
|
3
5
|
export function useArrowNavigation(items: any, isOpen: any) {
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
+
const selectItem = ref<ItemType | null>(null)
|
|
7
|
+
const highlightIndex = ref<number>(-1)
|
|
8
|
+
|
|
9
|
+
const itemsData = computed(() => (isRef(items) ? items.value : items))
|
|
10
|
+
const isMenuOpen = computed(() => (isRef(isOpen) ? isOpen.value : isOpen))
|
|
6
11
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
const selectedItem = computed({
|
|
13
|
+
get: () => selectItem.value,
|
|
14
|
+
set: (value: ItemType) => {
|
|
15
|
+
selectItem.value = value
|
|
10
16
|
}
|
|
11
|
-
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
})
|
|
18
|
+
const highlightedIndex = computed({
|
|
19
|
+
get: () => highlightIndex.value,
|
|
20
|
+
set: (value: number) => {
|
|
21
|
+
highlightIndex.value = value
|
|
15
22
|
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const itemsLength = computed<number>(() => itemsData.value.length)
|
|
26
|
+
|
|
27
|
+
const decrementHighlightedIndex = (): void => {
|
|
28
|
+
highlightedIndex.value -= 1
|
|
16
29
|
}
|
|
17
|
-
const
|
|
18
|
-
|
|
30
|
+
const incrementHighlightedIndex = (): void => {
|
|
31
|
+
highlightedIndex.value += 1
|
|
32
|
+
}
|
|
33
|
+
const resetHighlightedIndex = (): void => {
|
|
34
|
+
highlightedIndex.value = -1
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isEligibleToHandleEnter = computed<boolean>(() => {
|
|
38
|
+
return (
|
|
19
39
|
highlightedIndex.value >= 0 &&
|
|
20
|
-
highlightedIndex.value <
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
40
|
+
highlightedIndex.value < itemsLength.value
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
const isEligibleToIncrementHighlightedIndex = computed<boolean>(() => {
|
|
44
|
+
return highlightedIndex.value < itemsLength.value - 1
|
|
45
|
+
})
|
|
46
|
+
const isEligibleToDecrementHighlightedIndex = computed<boolean>(() => {
|
|
47
|
+
return highlightedIndex.value > 0
|
|
48
|
+
})
|
|
49
|
+
const isNotEligibleToHandleArrows = computed<boolean>(() => {
|
|
50
|
+
return !itemsLength.value || !isMenuOpen.value
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
const handleArrowUp = (event: KeyboardEvent) => {
|
|
54
|
+
event.preventDefault()
|
|
55
|
+
if (isEligibleToDecrementHighlightedIndex.value) {
|
|
56
|
+
decrementHighlightedIndex()
|
|
24
57
|
}
|
|
25
58
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
59
|
+
const handleArrowDown = (event: KeyboardEvent) => {
|
|
60
|
+
event.preventDefault()
|
|
61
|
+
if (isEligibleToIncrementHighlightedIndex.value) {
|
|
62
|
+
incrementHighlightedIndex()
|
|
63
|
+
}
|
|
28
64
|
}
|
|
65
|
+
const handleEnter = () => {
|
|
66
|
+
if (isEligibleToHandleEnter.value) {
|
|
67
|
+
selectedItem.value = itemsData.value[highlightedIndex.value]
|
|
68
|
+
resetHighlightedIndex()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
29
72
|
const navigateList = (event: KeyboardEvent) => {
|
|
30
|
-
if (
|
|
73
|
+
if (isNotEligibleToHandleArrows.value) {
|
|
31
74
|
return
|
|
32
75
|
}
|
|
33
76
|
switch (event.key) {
|
|
34
77
|
case 'ArrowUp':
|
|
35
|
-
handleArrowUp()
|
|
78
|
+
handleArrowUp(event)
|
|
36
79
|
break
|
|
37
80
|
case 'ArrowDown':
|
|
38
|
-
handleArrowDown()
|
|
81
|
+
handleArrowDown(event)
|
|
39
82
|
break
|
|
40
83
|
case 'Enter':
|
|
41
84
|
handleEnter()
|
package/src/hooks/use-portal.ts
CHANGED
|
@@ -59,11 +59,7 @@ export default function (
|
|
|
59
59
|
|
|
60
60
|
if (portalIsActive.value === false) {
|
|
61
61
|
if (onGlobalDialog === false && portalEl.value === null) {
|
|
62
|
-
portalEl.value = createGlobalNode(
|
|
63
|
-
portalEl.value.className =
|
|
64
|
-
portalEl.value.className + (parentClass || '')
|
|
65
|
-
portalEl.value.style.cssText =
|
|
66
|
-
portalEl.value.style.cssText + (parentStyle || '')
|
|
62
|
+
portalEl.value = createGlobalNode()
|
|
67
63
|
}
|
|
68
64
|
|
|
69
65
|
portalIsActive.value = true
|