Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] The popover would not disappear when wrapping disabled button #550

Closed
light049 opened this issue Mar 30, 2022 · 7 comments
Closed
Labels
🐛 bug Something isn't working

Comments

@light049
Copy link
Contributor

light049 commented Mar 30, 2022

Descriptions

The popover would not disappear as expected when wrapping a disabled button.

Workaround

As a reference to get expected results

@light049 light049 changed the title The popover would not disappear when wrapping disabled button [Issue] The popover would not disappear when wrapping disabled button Mar 30, 2022
@cheton
Copy link
Member

cheton commented Mar 30, 2022

@light049
Related to facebook/react#18753

Pointer Events should have been supported by modern browsers and React v16.4

@cheton cheton added the 🐛 bug Something isn't working label Mar 30, 2022
@cheton cheton linked a pull request Mar 30, 2022 that will close this issue
@cheton
Copy link
Member

cheton commented Mar 30, 2022

@light049 This issue will be resolved in PR #551

You can use the follwoing code as a temporary workaround while waiting for a hotfix release.

<Popover trigger="hover">
  <PopoverTrigger>
    {({ getPopoverTriggerProps }) => {
      const popoverTriggerProps = getPopoverTriggerProps();
      popoverTriggerProps.onPointerEnter = popoverTriggerProps.onMouseEnter;
      popoverTriggerProps.onPointerLeave = popoverTriggerProps.onMouseLeave;
      popoverTriggerProps.onPointerMove = popoverTriggerProps.onMouseMove;
      return ( 
        <Button disabled {...popoverTriggerProps}>Disabled Button</Button>
      );
    }}
  </PopoverTrigger>
  <PopoverContent>
    Popover
  </PopoverContent>
</Popover>

@light049
Copy link
Contributor Author

light049 commented Mar 30, 2022

@cheton Thanks for your example.
I meet another weird condition if I abstract the button component out to be another component.
The popover content would not localed at expected position.

const Btn = ({
  disabled,
  ...restProps
}) => {
  return ( 
    <Button disabled {...restProps}>Disabled Button</Button>
  );
};

const Example = () => {
  return (
    <Popover trigger="hover">
      <PopoverTrigger>
        {({ getPopoverTriggerProps }) => {
          const popoverTriggerProps = getPopoverTriggerProps();
          popoverTriggerProps.onPointerEnter = popoverTriggerProps.onMouseEnter;
          popoverTriggerProps.onPointerLeave = popoverTriggerProps.onMouseLeave;
          popoverTriggerProps.onPointerMove = popoverTriggerProps.onMouseMove;
          return ( 
            <Btn disabled {...popoverTriggerProps} />
          );
        }}
      </PopoverTrigger>
      <PopoverContent>
        Popover
      </PopoverContent>
    </Popover>  
  );
}

@cheton
Copy link
Member

cheton commented Mar 30, 2022

You have to wrap your component using forwardRef:

const Btn = forwardRef((
  {
    disabled,
    ...restProps
  },
  ref,
) => {
  return ( 
    <Button ref={ref} disabled {...restProps}>Disabled Button</Button>
  );
});

@atomiks
Copy link

atomiks commented Apr 3, 2022

FYI pointer events (in the nature of fixing this bug, not the support in general) don't work in Safari also so I wouldn't consider it a solution. It's a problem with React's delegation/synthetic system: https://twitter.com/atomiksdev/status/1510512851198242819

@cheton
Copy link
Member

cheton commented Apr 8, 2022

@atomiks @light049 This issue is related to facebook/react#11972

See https://github.com/chakra-ui/chakra-ui/blob/next/packages/tooltip/src/use-tooltip.ts

  /**
   * This allows for catching mouseleave events when the tooltip
   * trigger is disabled. There's currently a known issue in
   * React regarding the onMouseLeave polyfill.
   * @see https://github.com/facebook/react/issues/11972
   */
  useEventListener("mouseleave", closeWithDelay, () => ref.current)

The workaround is to listen to the native mouseleave event to mitigate the known issue.

@cheton
Copy link
Member

cheton commented Apr 15, 2022

Fixed in #561

@cheton cheton closed this as completed Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants