@@ -21,11 +21,11 @@ import {
2121
2222import { getWindow , raf } from "@qualcomm-ui/dom/query"
2323import { noop , runIfFn } from "@qualcomm-ui/utils/functions"
24- import { isNull } from "@qualcomm-ui/utils/guard"
2524import { compact } from "@qualcomm-ui/utils/object"
2625
2726import { getAnchorElement } from "./get-anchor"
2827import {
28+ cssVars ,
2929 rectMiddleware ,
3030 shiftArrowMiddleware ,
3131 transformOriginMiddleware ,
@@ -43,7 +43,6 @@ const defaultOptions: PositioningOptions = {
4343 arrowSelector : "[data-part=arrow]" ,
4444 fitViewport : false ,
4545 flip : true ,
46- gutter : 8 ,
4746 listeners : true ,
4847 overflowPadding : 8 ,
4948 overlap : false ,
@@ -63,7 +62,6 @@ interface Options extends RequiredBy<
6362 | "strategy"
6463 | "placement"
6564 | "listeners"
66- | "gutter"
6765 | "flip"
6866 | "slide"
6967 | "overlap"
@@ -93,18 +91,25 @@ function getArrowMiddleware(arrowElement: HTMLElement | null, opts: Options) {
9391 } )
9492}
9593
96- function getOffsetMiddleware ( arrowElement : HTMLElement | null , opts : Options ) {
97- if ( isNull ( opts . offset ?? opts . gutter ) ) {
98- return
94+ function getOffsetMiddleware (
95+ arrowElement : HTMLElement | null ,
96+ opts : Options ,
97+ contextEl ?: Element | null ,
98+ ) {
99+ let cssGutter : number | undefined
100+ if ( contextEl ) {
101+ const parsed = parseFloat (
102+ getComputedStyle ( contextEl ) . getPropertyValue ( cssVars . gutter . variable ) ,
103+ )
104+ if ( ! Number . isNaN ( parsed ) ) {
105+ cssGutter = parsed
106+ }
99107 }
108+
100109 return offset ( ( { placement} ) => {
101110 const arrowOffset = ( arrowElement ?. clientHeight || 0 ) / 2
102-
103- const gutter = opts . offset ?. mainAxis ?? opts . gutter
104- const mainAxis =
105- typeof gutter === "number"
106- ? gutter + arrowOffset
107- : ( gutter ?? arrowOffset )
111+ const gutter = opts . offset ?. mainAxis ?? opts . gutter ?? cssGutter ?? 2
112+ const mainAxis = gutter + arrowOffset
108113
109114 const { hasAlign} = getPlacementDetails ( placement )
110115 const shift = ! hasAlign ? opts . shift : undefined
@@ -206,7 +211,7 @@ function getPlacementImpl(
206211 const arrowEl = floating . querySelector < HTMLElement > ( options . arrowSelector )
207212
208213 const middleware : ( Middleware | undefined ) [ ] = [
209- getOffsetMiddleware ( arrowEl , options ) ,
214+ getOffsetMiddleware ( arrowEl , options , reference . contextElement ) ,
210215 getFlipMiddleware ( options ) ,
211216 getShiftMiddleware ( options ) ,
212217 getArrowMiddleware ( arrowEl , options ) ,
0 commit comments