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

[@mantine/core] always try centering arrow on target for popover #3065

Merged
merged 2 commits into from Nov 28, 2022

Conversation

jvdsande
Copy link
Contributor

This PR tries to fix some outstanding issues introduced with the switch to Floating UI:

  • Position of the arrow is now correctly recomputed when the dropdown shifts to stay in viewport even when placement is -end or `-start``
  • To fix the point above, a change was introduced: -end and -start placement now only impact the dropdown, not the arrow. The arrow will always try to align itself on the center of the target.
  • arrowOffset now acts as a min distance from dropdown border, rather than a fixed position in -end and -start placement.
  • When placement/position is dynamic, scroll/window resize would reset everything to the initial values on first mount. This is now fixed by remounting the dropdown when the placement/position changes
  • The arrow was not correctly positioned and the border was wrong in RTL mode. This is fixed by actually removing any RTL-specific styling, as Floating UI already handles thi internally.

@jvdsande jvdsande force-pushed the feat/popover-arrow-positioning branch from d15e5bd to a80de1f Compare November 26, 2022 10:23
import { getArrowPositionStyles } from './get-arrow-position-styles';
import { FloatingPosition } from '../types';

interface FloatingArrowProps extends React.ComponentPropsWithoutRef<'div'> {
withBorder: boolean;
position: FloatingPosition;
arrowSize: number;
arrowOffset: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the arrow offset anymore in this component, as the offset is now used as a configuration for the arrow middleware of floating UI directly.

},
ref
) => {
const theme = useMantineTheme();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the theme at all anymore since the RTL direction is already handled by Floating UI

}

return {};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two functions are not needed anymore, as position is correctly handled by Floating UI, including RTL. So we can directly set left for vertical and top for horizontal sides

top: arrowPosition,
borderBottom: 0,
[dir === 'ltr' ? 'borderRight' : 'borderLeft']: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check was actually messing things up for RTL, simply removing it fixes things

@rtivital
Copy link
Member

Looks good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants