Skip to content

Commit d150440

Browse files
committed
add config for shift amount
1 parent 07390a1 commit d150440

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: packages/plugins/plugin-tooltip/src/tooltip-provider.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export interface TooltipProviderOptions {
2626
crossAxis?: number
2727
alignmentAxis?: number | null
2828
}
29+
// The amount to shift the block by. Default is 0.
30+
shift?: number
2931
/// Other middlewares for floating ui. This will be added after the internal middlewares.
3032
middleware?: Middleware[]
3133
/// Options for floating ui. If you pass `middleware` or `placement`, it will override the internal settings.
@@ -62,7 +64,8 @@ export class TooltipProvider {
6264
crossAxis?: number
6365
alignmentAxis?: number | null
6466
}
65-
67+
/// @internal
68+
readonly #shift?: number
6669
/// The root element of the tooltip.
6770
element: HTMLElement
6871

@@ -77,6 +80,7 @@ export class TooltipProvider {
7780
this.#debounce = options.debounce ?? 200
7881
this.#shouldShow = options.shouldShow ?? this.#_shouldShow
7982
this.#offset = options.offset
83+
this.#shift = options.shift
8084
this.#middleware = options.middleware ?? []
8185
this.#floatingUIOptions = options.floatingUIOptions ?? {}
8286
this.#root = options.root
@@ -111,7 +115,7 @@ export class TooltipProvider {
111115
}
112116
computePosition(virtualEl, this.element, {
113117
placement: this.#floatingUIOptions.placement ?? 'top',
114-
middleware: [flip(), offset(this.#offset), shift(), ...this.#middleware],
118+
middleware: [flip(), offset(this.#offset), shift(this.#shift), ...this.#middleware],
115119
}).then(({ x, y }) => {
116120
Object.assign(this.element.style, {
117121
left: `${x}px`,
@@ -159,7 +163,7 @@ export class TooltipProvider {
159163
if (virtualElement) {
160164
computePosition(virtualElement, this.element, {
161165
placement: 'top',
162-
middleware: [flip(), offset(this.#offset), shift()],
166+
middleware: [flip(), offset(this.#offset), shift(this.#offset)],
163167
...this.#floatingUIOptions,
164168
}).then(({ x, y }) => {
165169
Object.assign(this.element.style, {

0 commit comments

Comments
 (0)