Skip to content

Scale transition conflicts with the translate transform #2470

Description

@hornta

I'm having problems implementing a transition for my popover component that uses CSS transform with scale because it overrides the translate property. Currently what I've achieved is this but the problem is that the transition styles overrides the transform position from floating-ui itself.

The transitions works(apart from the transform origin) but the position is lost.

f7653d6e-4249-4d5f-96cc-c90feb48cda7

import {
  useMergeRefs,
  FloatingPortal,
  FloatingFocusManager,
  useTransitionStyles,
} from "@floating-ui/react";
import { HTMLProps, forwardRef } from "react";
import { usePopoverContext } from "./PopoverContext.ts";

export const PopoverContent = forwardRef<
  HTMLDivElement,
  HTMLProps<HTMLDivElement>
>(function PopoverContent({ style, ...props }, propRef) {
  const { context: floatingContext, ...context } = usePopoverContext();
  const ref = useMergeRefs([context.refs.setFloating, propRef]);

  const { styles: transitionStyles, isMounted } = useTransitionStyles(
    floatingContext,
    {
      duration: 100,
      initial: {
        opacity: 0,
        transform: "scale(0)",
      },
      open: {
        opacity: 1,
        transform: "scale(1)",
      },
    },
  );

  if (!isMounted) {
    return null;
  }

  return (
    <FloatingPortal>
      <FloatingFocusManager context={floatingContext} modal={context.modal}>
        <div
          ref={ref}
          style={{ ...context.floatingStyles, ...transitionStyles, ...style }}
          aria-labelledby={context.labelId}
          aria-describedby={context.descriptionId}
          {...context.getFloatingProps(props)}
        >
          {props.children}
        </div>
      </FloatingFocusManager>
    </FloatingPortal>
  );
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions