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

Update EuiComboBox to match options list width to the input width. #611

Merged
merged 1 commit into from
Apr 3, 2018
Merged
Show file tree
Hide file tree
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
23 changes: 12 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
# [`master`](https://github.com/elastic/eui/tree/master)

- Modifying drop shadow intensities and color. ([607](https://github.com/elastic/eui/pull/607))
- Removed extraneous `global_styling/mixins/_forms.scss` file and importing the correct files in the `filter_group.scss` and `combo_box.scss` files. ([609](https://github.com/elastic/eui/pull/609))
- Modified drop shadow intensities and color. ([#607](https://github.com/elastic/eui/pull/607))
- Removed extraneous `global_styling/mixins/_forms.scss` file and importing the correct files in the `filter_group.scss` and `combo_box.scss` files. ([#609](https://github.com/elastic/eui/pull/609))

**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))
- Fixed a typo in the flex TypeScript definition ([629](https://github.com/elastic/eui/pull/629))
- 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 a typo in the flex TypeScript definition ([#629](https://github.com/elastic/eui/pull/629))
- 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