Skip to content

Commit 36adc3f

Browse files
committed
feat(vueltip): allow null and undefined as value
1 parent 47d4660 commit 36adc3f

4 files changed

Lines changed: 25 additions & 13 deletions

File tree

.changeset/neat-garlics-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vingy/vueltip": minor
3+
---
4+
5+
allow undefined and null as value

packages/vueltip/src/directive.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ import type {
1515
} from './types.ts'
1616
import { ensureKey } from './utils'
1717

18-
const toContent = (value: Binding): Content =>
19-
typeof value === 'string'
20-
? { text: value }
21-
: typeof value.content === 'string'
22-
? { text: value.content }
23-
: value.content
24-
18+
const toContent = (value: Binding): Content => {
19+
if (value == null) return { text: value }
20+
if (typeof value === 'string') return { text: value }
21+
if (value.content == null) return { text: value.content }
22+
if (typeof value.content === 'string')
23+
return { text: value.content }
24+
return value.content
25+
}
2526
const extractPlacement = (
2627
binding: DirectiveBinding<Binding, Modifier, Placement>,
2728
) => {
2829
const { value, arg } = binding
2930

30-
if (typeof value !== 'string' && 'placement' in value) {
31+
if (
32+
value &&
33+
typeof value !== 'string' &&
34+
'placement' in value
35+
) {
3136
return value.placement
3237
}
3338
if (!arg) return getOption('defaultPlacement')

packages/vueltip/src/listeners.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ export const onMouseover = ensureEventTarget((target) =>
3232
const { text } = content
3333

3434
if (
35-
elementContainsText(target, text) &&
36-
!isTruncated(target)
35+
!text ||
36+
(elementContainsText(target, text) &&
37+
!isTruncated(target))
3738
) {
3839
return
3940
}

packages/vueltip/src/types.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import type {
22
Placement,
33
UseFloatingOptions,
44
} from '@floating-ui/vue'
5+
import { Maybe } from '@vingy/shared/types'
56
import type { Directive, ShallowRef } from 'vue'
67

78
export interface Content {
8-
text: string
9+
text: Maybe<string>
910
}
1011
export type Binding =
11-
| string
12+
| Maybe<string>
1213
| {
13-
content: string | Content
14+
content: Maybe<string | Content>
1415
placement: Placement
1516
}
1617
export type Modifier = 'x' | 'y' | 'none' | 'both'

0 commit comments

Comments
 (0)