From d368e53b30f5d4d52a7d254314deb2b37512de75 Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Sun, 26 Apr 2026 10:44:52 -0500 Subject: [PATCH] add some comments --- client/components/anchorPositioningPolyfill.js | 7 +++++++ client/components/dropdown/dropdown.jsx | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/components/anchorPositioningPolyfill.js b/client/components/anchorPositioningPolyfill.js index 0a0d58fa1..92050a45a 100644 --- a/client/components/anchorPositioningPolyfill.js +++ b/client/components/anchorPositioningPolyfill.js @@ -1,7 +1,14 @@ +/* +This file basically checks support for Anchor Positioning API in the browser, +and then loads the Oddbird polyfill if support is lacking. +*/ + let polyfillPromise; +// look for `anchorName` in the computed styles const supportsAnchorPositioning = ()=>'anchorName' in document.documentElement.style; +// wait for initial render const afterInitialRender = ()=>new Promise((resolve)=>{ requestAnimationFrame(()=>{ requestAnimationFrame(resolve); diff --git a/client/components/dropdown/dropdown.jsx b/client/components/dropdown/dropdown.jsx index 2efeac776..9ace9cca3 100644 --- a/client/components/dropdown/dropdown.jsx +++ b/client/components/dropdown/dropdown.jsx @@ -2,13 +2,17 @@ * A dropdown menu component that uses the Anchor Positioning API to position the elements. It supports nested submenus as well. * Anchor Positioning is now supported in all major browsers. If support is needed for older browsers (namely, older firefox) * it is possible to use absolute positioning and calculations/resize observers to position things well enough, but adds another layer of complexity to the code. + * + * As-is, the menus will always open down aligned on left to trigger, submenus open to the right initially. + * If no space, menus will still open down, but aligned to the right of the trigger. Submenus will flip to the other side of the top menu. + * This could be customized either in more specific CSS, or as a `direction` prop on the component (in future iterations). + * * @param {string} props.groupName - Name of the menu. Appears as the trigger text. * @param {string} [props.icon] - Icon to display in the trigger. * @param {string} [props.color] - Color class to add to the trigger. * @param {string} [props.className] - Additional classes for the menu wrapper. * @param {React.ReactNode} [props.customTrigger] - Custom element to use as a trigger. * @param {React.ReactNode} [props.children] - Child elements to render in the menu. - * @param {'right'|'left'} [props.dir] - Preferred menu open direction. Currently does nothing. * @returns {React.JSX.Element} */ @@ -19,7 +23,7 @@ import _ from 'lodash'; // use react context to keep track of the menu depth (menus in menus) const MenuDepthContext = React.createContext(0); -const Dropdown = ({ groupName, className = null, icon, children, color = null, customTrigger, dir = 'right', ...props })=>{ +const Dropdown = ({ groupName, className = null, icon, children, color = null, customTrigger, ...props })=>{ const menuId = `${_.kebabCase(groupName)}-menu`; const anchorName = `--${menuId}`; const depth = React.useContext(MenuDepthContext); @@ -27,7 +31,6 @@ const Dropdown = ({ groupName, className = null, icon, children, color = null, c // A menu is a submenu if depth > 0 const isSubMenu = depth > 0; - const wrapperRef = useRef(null); const triggerRef = useRef(null); const menuRef = useRef(null); @@ -70,7 +73,7 @@ const Dropdown = ({ groupName, className = null, icon, children, color = null, c }; return ( -
+