Skip to content

Commit

Permalink
fix: Adjusting the width of dropdown (#18059)
Browse files Browse the repository at this point in the history
* fix: Adjusting the width of dropdown

This will make it so the width of the dropdown will adjust to the longest variable name

* fix: Adjusting the width of dropdown

Updating font

* fix: Adjusting the width of dropdown

fix prettier
  • Loading branch information
zoesteinkamp authored May 14, 2020
1 parent 97037f8 commit 17f4cc1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ui/src/variables/components/VariableDropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@
cursor: grab !important;
}
}

.variable-dropdown--item {
font-family: $cf-code-font;
}
10 changes: 10 additions & 0 deletions ui/src/variables/components/VariableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ class VariableDropdown extends PureComponent<Props> {
const dropdownStatus =
values.length === 0 ? ComponentStatus.Disabled : ComponentStatus.Default

const longestItemWidth = Math.floor(
values.reduce(function(a, b) {
return a.length > b.length ? a : b
}, '').length * 8.5
)

const widthLength = Math.max(140, longestItemWidth)

return (
<div className="variable-dropdown">
{/* TODO: Add variable description to title attribute when it is ready */}
Expand All @@ -62,6 +70,7 @@ class VariableDropdown extends PureComponent<Props> {
)}
menu={onCollapse => (
<Dropdown.Menu
style={{width: `${widthLength}px`}}
onCollapse={onCollapse}
theme={DropdownMenuTheme.Amethyst}
>
Expand All @@ -74,6 +83,7 @@ class VariableDropdown extends PureComponent<Props> {
onClick={this.handleSelect}
selected={val === selectedValue}
testID="variable-dropdown--item"
className="variable-dropdown--item"
>
{val}
</Dropdown.Item>
Expand Down

0 comments on commit 17f4cc1

Please sign in to comment.