From 769e47cdb046be84088bc075f04e1f90161953f1 Mon Sep 17 00:00:00 2001 From: chancestrickland Date: Fri, 7 Feb 2020 15:12:32 -0800 Subject: [PATCH] popover: adjust default collisions to take button width into account (#460) --- .../menu-button/examples/long-text.example.js | 62 +++++++++---------- packages/popover/src/index.tsx | 21 +------ 2 files changed, 29 insertions(+), 54 deletions(-) diff --git a/packages/menu-button/examples/long-text.example.js b/packages/menu-button/examples/long-text.example.js index 388faf35d..430ac7494 100644 --- a/packages/menu-button/examples/long-text.example.js +++ b/packages/menu-button/examples/long-text.example.js @@ -5,7 +5,7 @@ import { MenuList, MenuLink, MenuButton, - MenuItem + MenuItem, } from "@reach/menu-button"; import "@reach/menu-button/styles.css"; @@ -14,45 +14,39 @@ let name = "Long Text"; function Example() { return ( <> - - - Developers Developers Developers Developers - - - Download - Create a Copy - Mark as Draft - Delete - - Attend a Workshop Attend a Workshop Attend a Workshop Attend a - Workshop Attend a Workshop - - -
- - - Developers Developers Developers Developers{" "} - - - - Download - Create a Copy - - Mark as Draft - - Delete - - Attend a Workshop Attend a Workshop Attend a Workshop Attend a - Workshop Attend a Workshop - - - + +
+
+ +
+
+
); } +function MyMenu() { + return ( + + + Developers Developers Developers Developers + + + Download + Create a Copy + Mark as Draft + Delete + + Attend a Workshop Attend a Workshop Attend a Workshop Attend a + Workshop Attend a Workshop + + + + ); +} + Example.story = { name }; export const Comp = Example; export default { title: "MenuButton" }; diff --git a/packages/popover/src/index.tsx b/packages/popover/src/index.tsx index bd3a398c5..7c431bd15 100644 --- a/packages/popover/src/index.tsx +++ b/packages/popover/src/index.tsx @@ -123,25 +123,6 @@ export const positionMatchWidth: Position = (targetRect, popoverRect) => { }; }; -// Finish this another time -// export function positionHorizontalCenter(targetRect, popoverRect) { -// const targetCenter = targetRect.width / 2 + targetRect.left; -// const popoverHalf = popoverRect.width / 2; - -// const collisions = { -// right: window.innerWidth < targetCenter - popoverHalf, -// left: targetCenter - popoverHalf < 0 -// // top: -// // bottom: -// }; - -// return { -// left: collisions.right -// ? `${targetRect.right - popoverRect.width + window.pageXOffset}px` -// : collisions.left ? `` : `` -// }; -// } - function getCollisions( targetRect: PRect, popoverRect: PRect, @@ -154,7 +135,7 @@ function getCollisions( bottom: window.innerHeight < targetRect.bottom + popoverRect.height - offsetBottom, - left: targetRect.left - popoverRect.width < 0, + left: targetRect.left + targetRect.width - popoverRect.width < 0, }; const directionRight = collisions.right && !collisions.left;