From e3f29cd23ca1fd0f24efba5101334ecae31b68da Mon Sep 17 00:00:00 2001 From: Gorka Ludlow Date: Tue, 1 Oct 2019 10:39:03 -0400 Subject: [PATCH] Dropdown & Popover fixes for dimensions and scrolling (#608) DropDown: add mask for label Popover: use container boundaries to avoid overflow; add scrolling --- src/components/DropDown/DropDown.js | 27 ++++++++++++++------------- src/components/Popover/Popover.js | 13 ++++++++++++- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/components/DropDown/DropDown.js b/src/components/DropDown/DropDown.js index 973322fe6..9d8a135f6 100644 --- a/src/components/DropDown/DropDown.js +++ b/src/components/DropDown/DropDown.js @@ -112,24 +112,22 @@ const DropDown = React.memo(function DropDown({ const { width: vw } = useViewport() const [widthNoPx = MIN_WIDTH] = (width || '').split('px') - const [placeholderMinWidth, setPlaceholderMinWidth] = useState( - Math.min(widthNoPx, MIN_WIDTH) - ) const [buttonWidth, setButtonWidth] = useState(0) - const [getContentWidth, setGetContentWidth] = useState(true) + const [measureWidth, setMeasureWidth] = useState(true) // Adjust the button width if the item widths are larger than declared width + const [placeholderMinWidth, setPlaceholderMinWidth] = useState( + Math.min(widthNoPx, MIN_WIDTH) + ) const popoverRefCallback = useCallback(el => { if (!el) { return } - // Add 4 GU to accomodate for caret spacing - setPlaceholderMinWidth(el.clientWidth + 4 * GU) - setGetContentWidth(false) + setPlaceholderMinWidth(el.clientWidth) + setMeasureWidth(false) }, []) - // Re-adjust if the width or items ever change useEffect(() => { - setGetContentWidth(true) + setMeasureWidth(true) }, [vw, items]) // Update the button width every time the reference updates @@ -187,7 +185,7 @@ const DropDown = React.memo(function DropDown({ padding-left: ${2 * GU}px; padding-right: ${1.5 * GU}px; width: ${width || (wide ? '100%' : 'auto')}; - min-width: ${placeholderMinWidth}px; + min-width: ${wide ? 'auto' : `${placeholderMinWidth}px`}; background: ${disabled ? theme.disabled : theme.surface}; color: ${disabled ? theme.disabledContent : theme.surfaceContent}; border: ${disabled ? 0 : 1}px solid @@ -203,7 +201,9 @@ const DropDown = React.memo(function DropDown({ `} {...props} > -