Skip to content

Commit

Permalink
Update EuiComboBox to match options list width to the input width.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Apr 2, 2018
1 parent d59b6b8 commit e52330e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

**Bug fixes**

- Visual fix for the focus state of disabled `EuiButton` ([603](https://github.com/elastic/eui/pull/603))
- `EuiSelect` can pass any node as a value rather than just a string ([603](https://github.com/elastic/eui/pull/603))

- Visual fix for the focus state of disabled `EuiButton` ([#603](https://github.com/elastic/eui/pull/603))
- `EuiSelect` can pass any node as a value rather than just a string ([#603](https://github.com/elastic/eui/pull/603))
- Fixed `EuiComboBox` bug in which the options list wouldn't always match the width of the input ([#611](https://github.com/elastic/eui/pull/611))

# [`0.0.37`](https://github.com/elastic/eui/tree/v0.0.37)

- Added `EuiComboBox` for selecting many options from a list of options ([567](https://github.com/elastic/eui/pull/567))
- Added `EuiHighlight` for highlighting a substring within text ([567](https://github.com/elastic/eui/pull/567))
- `calculatePopoverPosition` service now accepts a `positions` argument so you can specify which positions are acceptable ([567](https://github.com/elastic/eui/pull/567))
- Added `closeButtonProps` prop to `EuiBadge`, `hollow` badge type, and support for arbitrary hex color ([567](https://github.com/elastic/eui/pull/567))
- Added support for arbitrary hex color to `EuiIcon` ([567](https://github.com/elastic/eui/pull/567))
- Added `EuiComboBox` for selecting many options from a list of options ([#567](https://github.com/elastic/eui/pull/567))
- Added `EuiHighlight` for highlighting a substring within text ([#567](https://github.com/elastic/eui/pull/567))
- `calculatePopoverPosition` service now accepts a `positions` argument so you can specify which positions are acceptable ([#567](https://github.com/elastic/eui/pull/567))
- Added `closeButtonProps` prop to `EuiBadge`, `hollow` badge type, and support for arbitrary hex color ([#567](https://github.com/elastic/eui/pull/567))
- Added support for arbitrary hex color to `EuiIcon` ([#567](https://github.com/elastic/eui/pull/567))

**Breaking changes**

- Renamed `euiBody-hasToolTip` class to `euiBody-hasPortalContent` ([567](https://github.com/elastic/eui/pull/567))
- Renamed `euiBody-hasToolTip` class to `euiBody-hasPortalContent` ([#567](https://github.com/elastic/eui/pull/567))

# [`0.0.36`](https://github.com/elastic/eui/tree/v0.0.36)

Expand Down
28 changes: 18 additions & 10 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class EuiComboBox extends Component {
searchValue: initialSearchValue,
isListOpen: false,
listPosition: 'bottom',
listStyles: {},
};

// Cached derived state.
Expand Down Expand Up @@ -100,19 +99,29 @@ export class EuiComboBox extends Component {
return;
}

// Cache for future calls.
this.listBounds = listBounds;
const comboBoxBounds = this.comboBox.getBoundingClientRect();
const { position, left, top } = calculatePopoverPosition(comboBoxBounds, listBounds, 'bottom', 0, ['bottom', 'top']);

const listStyles = {
top: top + window.scrollY,
left,
// Cache for future calls. Assign values directly instead of destructuring because listBounds is
// a DOMRect, not a JS object.
this.listBounds = {
bottom: listBounds.bottom,
height: listBounds.height,
left: comboBoxBounds.left,
right: comboBoxBounds.right,
top: listBounds.top,
width: comboBoxBounds.width,
x: listBounds.x,
y: listBounds.y,
};

const { position, left, top } = calculatePopoverPosition(comboBoxBounds, this.listBounds, 'bottom', 0, ['bottom', 'top']);

this.optionsList.style.top = `${top + window.scrollY}px`;
this.optionsList.style.left = `${left}px`;
this.optionsList.style.width = `${comboBoxBounds.width}px`;

this.setState({
listPosition: position,
listStyles,
});
};

Expand Down Expand Up @@ -432,7 +441,7 @@ export class EuiComboBox extends Component {
...rest
} = this.props;

const { searchValue, isListOpen, listStyles, listPosition } = this.state;
const { searchValue, isListOpen, listPosition } = this.state;

const classes = classNames('euiComboBox', className, {
'euiComboBox-isOpen': isListOpen,
Expand Down Expand Up @@ -461,7 +470,6 @@ export class EuiComboBox extends Component {
getSelectedOptionForSearchValue={getSelectedOptionForSearchValue}
updatePosition={this.updateListPosition}
position={listPosition}
style={listStyles}
renderOption={renderOption}
/>
</EuiPortal>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class EuiComboBoxOptionsList extends Component {
getSelectedOptionForSearchValue: PropTypes.func,
updatePosition: PropTypes.func.isRequired,
position: PropTypes.oneOf(POSITIONS),
style: PropTypes.object,
listRef: PropTypes.func.isRequired,
renderOption: PropTypes.func,
}
Expand Down

0 comments on commit e52330e

Please sign in to comment.