Skip to content

[EuiDragDrop][EuiPopover] Draggable is way out of the context when start dragging in popover #6314

Closed

Description

@nlatipov

Kibana 8.5
Eui 69.0.0

This happens when a drag and drop list is EuiPopover child. Here is the demo app https://codesandbox.io/s/distracted-flower-b52tet

Screenshot
Screen Shot 2022-10-18 at 01 02 00

In the screenshot I just started dragging

Notes:
This bug is similar to what happened before, for example #3548, where the solution was Replace translateZ with will-change #5806

Activity

  1. cee-chen commented on Oct 24, 2022

    @cee-chen
    Contributor

    @nlatipov Can you please include an animated screencap of the "way out of context" behavior you're seeing? I'm not seeing that as described on the linked CodeSandbox with latest Firefox:

    screencap

    Yes, there's a brief second where the draggable items are 5-10px or so off to the left but that's neither breaking nor an issue we would currently consider high priority.

  2. nlatipov commented on Oct 25, 2022

    @nlatipov
    Author

    @constancecchen made a new demo. added another div above the popover. Now the deviation is more visible.

    Screen.Recording.2022-10-25.at.08.53.15.mov

    Ultimately, this bug leads to the fact that when trying to implement a new feature, we see unexpected behavior in the drag and drop

    Screen.Recording.2022-10-20.at.16.44.28.mov
  3. alexwizp commented on Oct 25, 2022

    @alexwizp
    Contributor

    @constancecchen please have a look that and give us some recommendation what we can do with it. It's a blocker for us

  4. cee-chen commented on Oct 25, 2022

    @cee-chen
    Contributor

    Y'all are totally right, apologies. This is actually affecting our own drag & drop of items in our EuiDataGrid toolbar popovers as well in production (https://eui.elastic.co/v62.0.1/#/tabular-content/data-grid). I'm digging into this now but this bug appears to have started in v62.0.0, when EuiPopover was converted to Emotion.

    CC @chandlerprall for info, as I just added the urgent label to this

  5. cee-chen commented on Oct 25, 2022

    @cee-chen
    Contributor

    Hey y'all, after more digging I've discovered the issue.

    1. First things first, you always need to set transform: none !important; on any popover panels that contain drag & drop. This is because drag & drop does not work inside transformed elements. There is an example of our own EuiDataGrid using this workaround here:

      .euiDataGrid__controlPopoverWithDragDrop {
      // Hack because the fixed positions of drag and drop don't work inside of transformed elements
      // sass-lint:disable-block no-important
      transform: none !important;
      transition: none !important;
      margin-top: -$euiSizeS;
      }

    2. When EuiPopover was converted to Emotion, it started to use filter to create a drop shadow effect instead of box-shadow (I assume for modern CSS reasons/performance), causing our EuiDataGrid popover drag & drop to stop working.
      Unfortunately filter appears to create a stacking context that causes drag & drop to misbehave 💀 Since EuiPopover requires none workarounds (see 1.) in the first place to get drag context working, I'm leaning towards leaving the current CSS as-is and instead documenting the need to restore box-shadow manually.

    3. Putting that all together: here's what you need to get drag & drop inside popovers working: https://codesandbox.io/s/relaxed-elion-gkd0h7?file=/demo.js:1226-1664

    import { css } from '@emotion/react';
    import { useEuiTheme, euiShadowMedium } from '@elastic/eui';
    
    export const YourComponent = () => {
      const euiTheme = useEuiTheme();
    
      const panelCss = css`
        transform: none !important;
        transition: none !important;
        // Recreate the drop-shadow filter via box-shadow instead
        filter: none !important;
        ${euiShadowMedium(euiTheme)} // @include euiBottomShadow if using Sass
      `;
    
      return (
        <EuiPopover panelProps={{ css: panelCss }}>
           // Popover contents
        </EuiPopover>
      );
    }

    I realize that's not great and I'm debating adding some sort of helper or mixin within EUI to assist with not having to create your own overrides, or potentially a simpler hasDragDrop prop to EuiPopover itself. That will take a while to release/reach Kibana however, so in the interim the above CSS will unblock you until that gets in.

  6. nlatipov commented on Oct 25, 2022

    @nlatipov
    Author

    Thanks for resolving this issue so quickly. I looked it up in a demo project. And it seems to solve our problem. Tomorrow I will show the team.

    I hope the fix will be moved to the EUI soon and we will be able to clean up the kibana from this code

    Thanks guys

  7. cee-chen commented on Oct 27, 2022

    @cee-chen
    Contributor

    Anytime, I really appreciate the time y'all took to get a clear CodeSandbox to us!

    I've created a PR with a new hasDragDrop prop for EuiPopover (#6329). As a heads up it will likely take another 2-3+ weeks to get into Kibana.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions