Skip to content

Commit

Permalink
feat(popover): adhere to arrow size in gap (digdir#2661)
Browse files Browse the repository at this point in the history
resolves digdir#2657

This only solves it for popover, since tooltip does not have pseudo
element yet, Will solve this for tooltip in digdir#2656
  • Loading branch information
Barsnes authored Oct 23, 2024
1 parent f1edfac commit 71efc07
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/react/src/components/Popover/Popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import type { HTMLAttributes } from 'react';
import { useEffect } from 'react';
import { Context } from './PopoverContext';

const ARROW_HEIGHT = 7;
const ARROW_GAP = 4;

// Make React support popovertarget attribute
// https://github.com/facebook/react/issues/27479
declare global {
Expand Down Expand Up @@ -141,7 +138,14 @@ export const Popover = forwardRef<HTMLDivElement, PopoverProps>(
placement,
strategy: 'fixed',
middleware: [
offset(ARROW_HEIGHT + ARROW_GAP), // TODO: Should this be configurable?
offset((data) => {
// get pseudo element arrow size
const styles = getComputedStyle(
data.elements.floating,
'::before',
);
return parseFloat(styles.height);
}),
flip({ fallbackAxisSideDirection: 'start' }),
shift(),
arrowPseudoElement,
Expand Down

0 comments on commit 71efc07

Please sign in to comment.