-
Notifications
You must be signed in to change notification settings - Fork 127
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
Dropdown: elements min width #755
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,6 @@ import { useViewport } from '../../providers/Viewport/Viewport' | |
import ButtonBase from '../ButtonBase/ButtonBase' | ||
import Popover from '../Popover/Popover' | ||
|
||
const MIN_WIDTH = 128 | ||
|
||
function useDropDown({ | ||
buttonRef, | ||
items, | ||
|
@@ -111,26 +109,20 @@ const DropDown = React.memo(function DropDown({ | |
|
||
const theme = useTheme() | ||
const { width: vw } = useViewport() | ||
|
||
const [widthNoPx = MIN_WIDTH] = (width || '').split('px') | ||
const [buttonWidth, setButtonWidth] = useState(0) | ||
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 | ||
} | ||
setPlaceholderMinWidth(el.clientWidth) | ||
setMeasureWidth(false) | ||
}, []) | ||
useEffect(() => { | ||
setMeasureWidth(true) | ||
}, [vw, items]) | ||
|
||
console.log('measured width ', measureWidth) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remember to remove this when this is ready to review. 😃 |
||
// Update the button width every time the reference updates | ||
const { refCallback, buttonRef } = useButtonRef(el => { | ||
setButtonWidth(el.clientWidth) | ||
|
@@ -186,7 +178,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: ${wide ? 'auto' : `${placeholderMinWidth}px`}; | ||
min-width: auto; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need this to be set directly, because using The original behaviour was intended for the dropdown's width to fit all listed items, even if they were not selected. |
||
background: ${disabled ? theme.disabled : theme.surface}; | ||
color: ${disabled ? theme.disabledContent : theme.surfaceContent}; | ||
border: ${disabled ? 0 : 1}px solid | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we try and use
GU
here?