Skip to content

Commit

Permalink
Added support for fullWidth on EuiComboBox (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos authored Aug 7, 2018
1 parent a9e584e commit 2312d66
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Added `maxWidth` prop `EuiFlyout` ([#1090](https://github.com/elastic/eui/pull/1090))
- Added `string` to allowed `restrictWidth` prop type of `EuiPage` and `EuiPageBody` ([#1090](https://github.com/elastic/eui/pull/1090))
- Added `.eui-textBreakNormal` and `@mixin euiTextTruncate` as CSS/SASS utilities ([#1092](https://github.com/elastic/eui/pull/1092))
- Added `fullWidth` support to `EuiComboBox` ([#1095](https://github.com/elastic/eui/pull/1095))

**Bug fixes**

Expand Down
40 changes: 40 additions & 0 deletions src/components/combo_box/__snapshots__/combo_box.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ exports[`EuiComboBox is rendered 1`] = `
</div>
`;

exports[`props full width is rendered 1`] = `
<div
className="euiComboBox euiComboBox--fullWidth"
onFocus={[Function]}
onKeyDown={[Function]}
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={true}
hasSelectedOptions={true}
inputRef={[Function]}
isListOpen={false}
onChange={[Function]}
onClear={[Function]}
onClick={[Function]}
onCloseListClick={[Function]}
onFocus={[Function]}
onOpenListClick={[Function]}
onRemoveOption={[Function]}
searchValue=""
selectedOptions={
Array [
Object {
"label": "Mimas",
},
]
}
singleSelection={false}
toggleButtonRef={[Function]}
updatePosition={[Function]}
value="Mimas"
/>
</div>
`;

exports[`props isClearable=false disallows user from clearing input when no options are selected 1`] = `
<div
className="euiComboBox"
Expand All @@ -75,6 +110,7 @@ exports[`props isClearable=false disallows user from clearing input when no opti
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={false}
hasSelectedOptions={false}
inputRef={[Function]}
isListOpen={false}
Expand Down Expand Up @@ -102,6 +138,7 @@ exports[`props isClearable=false disallows user from clearing input when options
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={false}
hasSelectedOptions={true}
inputRef={[Function]}
isListOpen={false}
Expand Down Expand Up @@ -138,6 +175,7 @@ exports[`props isDisabled is rendered 1`] = `
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={false}
hasSelectedOptions={true}
inputRef={[Function]}
isDisabled={true}
Expand Down Expand Up @@ -255,6 +293,7 @@ exports[`props selectedOptions are rendered 1`] = `
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={false}
hasSelectedOptions={true}
inputRef={[Function]}
isListOpen={false}
Expand Down Expand Up @@ -292,6 +331,7 @@ exports[`props singleSelection is rendered 1`] = `
>
<EuiComboBoxInput
autoSizeInputRef={[Function]}
fullWidth={false}
hasSelectedOptions={true}
inputRef={[Function]}
isListOpen={false}
Expand Down
4 changes: 2 additions & 2 deletions src/components/combo_box/_combo_box.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.euiComboBox {
@include euiFormControlSize(auto);
@include euiFormControlSize(auto, $includeAlternates: true);
position: relative;

/**
Expand All @@ -8,7 +8,7 @@
* 3. The height on combo can be larger than normal text inputs.
*/
.euiComboBox__inputWrap {
@include euiFormControlStyle($includeStates: false, $includeSizes:false);
@include euiFormControlStyle($includeStates: false, $includeSizes: true);
@include euiFormControlWithIcon($isIconOptional: true);
@include euiFormControlSize(auto); /* 3 */

Expand Down
6 changes: 6 additions & 0 deletions src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export class EuiComboBox extends Component {
isInvalid: PropTypes.bool,
rowHeight: PropTypes.number,
isClearable: PropTypes.bool,
fullWidth: PropTypes.bool,
}

static defaultProps = {
options: [],
selectedOptions: [],
isClearable: true,
singleSelection: false,
fullWidth: false,
}

constructor(props) {
Expand Down Expand Up @@ -569,6 +571,7 @@ export class EuiComboBox extends Component {
isInvalid,
rowHeight,
isClearable,
fullWidth,
'data-test-subj': dataTestSubj,
...rest
} = this.props;
Expand All @@ -579,6 +582,7 @@ export class EuiComboBox extends Component {
'euiComboBox-isOpen': isListOpen,
'euiComboBox-isInvalid': isInvalid,
'euiComboBox-isDisabled': isDisabled,
'euiComboBox--fullWidth': fullWidth,
});

const value = selectedOptions.map(selectedOption => selectedOption.label).join(', ');
Expand Down Expand Up @@ -610,6 +614,7 @@ export class EuiComboBox extends Component {
onScroll={this.focusActiveOption}
rowHeight={rowHeight}
data-test-subj={optionsListDataTestSubj}
fullWidth={fullWidth}
/>
</EuiPortal>
);
Expand Down Expand Up @@ -645,6 +650,7 @@ export class EuiComboBox extends Component {
singleSelection={singleSelection}
isDisabled={isDisabled}
toggleButtonRef={this.toggleButtonRef}
fullWidth={fullWidth}
/>

{optionsList}
Expand Down
12 changes: 12 additions & 0 deletions src/components/combo_box/combo_box.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ describe('props', () => {

expect(component).toMatchSnapshot();
});

test('full width is rendered', () => {
const component = shallow(
<EuiComboBox
options={options}
selectedOptions={[options[2]]}
fullWidth={true}
/>
);

expect(component).toMatchSnapshot();
});
});

describe('behavior', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/components/combo_box/combo_box_input/combo_box_input.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';
import AutosizeInput from 'react-input-autosize';

Expand Down Expand Up @@ -31,6 +32,7 @@ export class EuiComboBoxInput extends Component {
singleSelection: PropTypes.bool,
isDisabled: PropTypes.bool,
toggleButtonRef: PropTypes.func,
fullWidth: PropTypes.bool,
}

constructor(props) {
Expand Down Expand Up @@ -91,6 +93,7 @@ export class EuiComboBoxInput extends Component {
singleSelection,
isDisabled,
toggleButtonRef,
fullWidth,
} = this.props;

const pills = selectedOptions.map((option) => {
Expand Down Expand Up @@ -166,13 +169,18 @@ export class EuiComboBoxInput extends Component {
'data-test-subj': 'comboBoxToggleListButton',
};

const wrapClasses = classNames('euiComboBox__inputWrap', {
'euiComboBox__inputWrap--fullWidth': fullWidth,
});

return (
<EuiFormControlLayout
icon={icon}
{...clickProps}
fullWidth={fullWidth}
>
<div
className="euiComboBox__inputWrap"
className={wrapClasses}
onClick={onClick}
data-test-subj="comboBoxInput"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* 3. The height can expand, hence auto
*/
.euiComboBoxOptionsList {
@include euiFormControlSize(auto); /* 3 */
@include euiFormControlSize(auto, $includeAlternates: true); /* 3 */
z-index: $euiZComboBox;
position: absolute; /* 2 */
top: 0; /* 2 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class EuiComboBoxOptionsList extends Component {
scrollToIndex: PropTypes.number,
onScroll: PropTypes.func,
rowHeight: PropTypes.number,
fullWidth: PropTypes.bool,
}

static defaultProps = {
Expand Down Expand Up @@ -110,6 +111,7 @@ export class EuiComboBoxOptionsList extends Component {
scrollToIndex,
onScroll,
rowHeight,
fullWidth,
'data-test-subj': dataTestSubj,
...rest
} = this.props;
Expand Down Expand Up @@ -208,7 +210,9 @@ export class EuiComboBoxOptionsList extends Component {
/>
);

const classes = classNames('euiComboBoxOptionsList', positionToClassNameMap[position]);
const classes = classNames('euiComboBoxOptionsList', positionToClassNameMap[position], {
'euiComboBoxOptionsList--fullWidth': fullWidth,
});

return (
<EuiPanel
Expand Down

0 comments on commit 2312d66

Please sign in to comment.