Browse Source

feat(dropdownMenu): Add `minMenuWidth` prop (#41040)

**Before:**
<img width="334" alt="Screen Shot 2022-11-04 at 2 36 03 PM"
src="https://user-images.githubusercontent.com/44172267/200078567-62d76845-18bc-43d3-946a-86485ffbab38.png">

**After:**
<img width="334" alt="Screen Shot 2022-11-04 at 2 35 39 PM"
src="https://user-images.githubusercontent.com/44172267/200078510-1649e7fe-f8bf-4ae6-b16d-aa4d5665a2b5.png">
Vu Luong 2 years ago
parent
commit
bf28bf1aa0

+ 6 - 7
static/app/components/dropdownMenu.tsx

@@ -40,20 +40,19 @@ type Props = {
    * Title to display on top of the menu
    * Title to display on top of the menu
    */
    */
   menuTitle?: string;
   menuTitle?: string;
-  onClose?: () => void;
-  size?: MenuItemProps['size'];
   /**
   /**
-   * Current width of the trigger element. This is used as the menu's minimum
-   * width.
+   * Minimum menu width
    */
    */
-  triggerWidth?: number;
+  minWidth?: number;
+  onClose?: () => void;
+  size?: MenuItemProps['size'];
 } & AriaMenuOptions<MenuItemProps> &
 } & AriaMenuOptions<MenuItemProps> &
   Partial<OverlayProps> &
   Partial<OverlayProps> &
   Partial<AriaPositionProps>;
   Partial<AriaPositionProps>;
 
 
 function DropdownMenu({
 function DropdownMenu({
   closeOnSelect = true,
   closeOnSelect = true,
-  triggerWidth,
+  minWidth,
   size,
   size,
   isSubmenu,
   isSubmenu,
   menuTitle,
   menuTitle,
@@ -201,7 +200,7 @@ function DropdownMenu({
             {...mergeProps(modifiedMenuProps, keyboardProps)}
             {...mergeProps(modifiedMenuProps, keyboardProps)}
             style={{
             style={{
               maxHeight: overlayPositionProps.style?.maxHeight,
               maxHeight: overlayPositionProps.style?.maxHeight,
-              minWidth: triggerWidth,
+              minWidth,
             }}
             }}
           >
           >
             {menuTitle && <MenuTitle>{menuTitle}</MenuTitle>}
             {menuTitle && <MenuTitle>{menuTitle}</MenuTitle>}

+ 6 - 1
static/app/components/dropdownMenuControl.tsx

@@ -79,6 +79,10 @@ interface Props
    * Title for the current menu.
    * Title for the current menu.
    */
    */
   menuTitle?: string;
   menuTitle?: string;
+  /**
+   * Minimum menu width, in pixels
+   */
+  minMenuWidth?: number;
   /**
   /**
    * Tag name for the outer wrap, defaults to `div`
    * Tag name for the outer wrap, defaults to `div`
    */
    */
@@ -123,6 +127,7 @@ function DropdownMenuControl({
   triggerProps = {},
   triggerProps = {},
   isDisabled: disabledProp,
   isDisabled: disabledProp,
   isOpen: isOpenProp,
   isOpen: isOpenProp,
+  minMenuWidth,
   isSubmenu = false,
   isSubmenu = false,
   closeRootMenu,
   closeRootMenu,
   closeCurrentSubmenu,
   closeCurrentSubmenu,
@@ -239,8 +244,8 @@ function DropdownMenuControl({
         {...props}
         {...props}
         {...menuProps}
         {...menuProps}
         size={size}
         size={size}
-        triggerWidth={triggerWidth}
         isSubmenu={isSubmenu}
         isSubmenu={isSubmenu}
+        minWidth={Math.max(minMenuWidth ?? 0, triggerWidth ?? 0)}
         closeRootMenu={closeRootMenu ?? state.close}
         closeRootMenu={closeRootMenu ?? state.close}
         closeCurrentSubmenu={closeCurrentSubmenu}
         closeCurrentSubmenu={closeCurrentSubmenu}
         disabledKeys={disabledKeys ?? defaultDisabledKeys}
         disabledKeys={disabledKeys ?? defaultDisabledKeys}

+ 1 - 0
static/app/views/issueList/savedIssueSearches.tsx

@@ -94,6 +94,7 @@ const SavedSearchItem = ({
           position="bottom-end"
           position="bottom-end"
           items={actions}
           items={actions}
           size="sm"
           size="sm"
+          minMenuWidth={200}
           trigger={props => (
           trigger={props => (
             <Button
             <Button
               {...props}
               {...props}