Skip to content
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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/components/DropDown/DropDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { useViewport } from '../../providers/Viewport/Viewport'
import ButtonBase from '../ButtonBase/ButtonBase'
import Popover from '../Popover/Popover'

const MIN_WIDTH = 128
Copy link
Contributor

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?


function useDropDown({
buttonRef,
items,
Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need this to be set directly, because using auto won't automatically adjust for the width of all items.

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
Expand Down