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

EuiComboBox additions #1139

Merged
merged 7 commits into from
Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `3.7.0`.

- Added color and monotone icons for AWS and GCP. ([#1135](https://github.com/elastic/eui/pull/1135))
- Added color and monotone icons for AWS and GCP ([#1135](https://github.com/elastic/eui/pull/1135))
- Added `singleSelection.asPlainText` prop to `EuiComboBox` ([#1139](https://github.com/elastic/eui/pull/1139))

## [`3.7.0`](https://github.com/elastic/eui/tree/v3.7.0)

Expand Down
8 changes: 5 additions & 3 deletions src-docs/src/views/combo_box/combo_box_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@ export const ComboBoxExample = {
}],
text: (
<p>
To only allow the user to select a single option, provide
the <EuiCode>singleSelection</EuiCode> prop.
To only allow the user to select a single option, provide the{' '}
<EuiCode>singleSelection</EuiCode> prop. You may want to render the selected option as
plain text instead of pill form. To do this, pass{' '}
<EuiCode>{'singleSelection={{ asPlainText: true }}'}</EuiCode>
</p>
),
props: { EuiComboBox },
Expand Down Expand Up @@ -257,7 +259,7 @@ export const ComboBoxExample = {
}],
text: (
<p>
Alternatively, provide thhe <EuiCode>noSuggestions</EuiCode> prop to hide the suggestions list
Alternatively, provide the <EuiCode>noSuggestions</EuiCode> prop to hide the suggestions list
and <em>only</em> allow the creation of custom options.
</p>
),
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/combo_box/single_selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class extends Component {
return (
<EuiComboBox
placeholder="Select a single option"
singleSelection={true}
singleSelection={{ asPlainText: true }}
Copy link
Contributor

@cjcenizal cjcenizal Aug 24, 2018

Choose a reason for hiding this comment

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

It seems like this will usually be the desired case, right? I can't think of a situation where we'd want the pill form for single selection. If you agree then how about we update the combo box to use asPlainText: true as default, while still giving people the option to specify false if for some reason they want the pill?

options={this.options}
selectedOptions={selectedOptions}
onChange={this.onChange}
Expand Down
4 changes: 2 additions & 2 deletions src/components/combo_box/__snapshots__/combo_box.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`EuiComboBox is rendered 1`] = `
class="euiFormControlLayout__childrenWrapper"
>
<div
class="euiComboBox__inputWrap"
class="euiComboBox__inputWrap euiComboBox__inputWrap-isClearable"
data-test-subj="comboBoxInput"
>
<div
Expand Down Expand Up @@ -214,7 +214,7 @@ exports[`props options list is rendered 1`] = `
class="euiFormControlLayout__childrenWrapper"
>
<div
class="euiComboBox__inputWrap"
class="euiComboBox__inputWrap euiComboBox__inputWrap-isClearable"
data-test-subj="comboBoxInput"
>
<div
Expand Down
23 changes: 15 additions & 8 deletions src/components/combo_box/_combo_box.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,23 @@
.euiComboBox__inputWrap {
@include euiFormControlStyle($includeStates: false, $includeSizes: true);
@include euiFormControlWithIcon($isIconOptional: true);
@include euiFormControlSize(auto); /* 3 */

@include euiFormControlSize();
padding: $euiSizeXS;
display: flex; /* 1 */
flex-wrap: wrap; /* 1 */
@include euiFormControlLayout__padding(2); /* 2 */
align-content: flex-start;
@include euiFormControlLayout__padding(1); /* 2 */

&.euiComboBox__inputWrap-isClearable {
@include euiFormControlLayout__padding(2); /* 2 */
}

&:not(.euiComboBox__inputWrap--noWrap) {
height: auto; /* 3 */
display: flex; /* 1 */
flex-wrap: wrap; /* 1 */
align-content: flex-start;

&:hover {
cursor: text;
&:hover {
cursor: text;
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/components/combo_box/combo_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export class EuiComboBox extends Component {
placeholder: PropTypes.string,
isLoading: PropTypes.bool,
async: PropTypes.bool,
singleSelection: PropTypes.bool,
singleSelection: PropTypes.oneOfType([
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this propType to also check for the asPlainText property, both here and in combo_box_input.js?

    singleSelection: PropTypes.oneOfType([
      PropTypes.bool,
      PropTypes.shape({
        asPlainText: PropTypes.bool,
      }),
    ]),

PropTypes.bool,
PropTypes.shape({
asPlainText: PropTypes.bool,
}),
]),
noSuggestions: PropTypes.bool,
options: PropTypes.array,
selectedOptions: PropTypes.array,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.euiComboBox__input {
max-width: 100%;

// Ensure that no input states are visible on the hidden input
input[aria-hidden="true"] {
Expand Down
10 changes: 10 additions & 0 deletions src/components/combo_box/combo_box_input/_combo_box_pill.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@
.euiComboBoxPill {
margin: $euiSizeXS !important;
line-height: $euiSizeL - 2px;

&--plainText {
font-size: $euiFontSizeS;
font-family: $euiFontFamily;
padding: 0 $euiSizeXS;
color: $euiTextColor;
vertical-align: middle;
display: inline-block;
@include euiTextTruncate;
}
}
15 changes: 13 additions & 2 deletions src/components/combo_box/combo_box_input/combo_box_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export class EuiComboBoxInput extends Component {
isListOpen: PropTypes.bool.isRequired,
onOpenListClick: PropTypes.func.isRequired,
onCloseListClick: PropTypes.func.isRequired,
singleSelection: PropTypes.bool,
singleSelection: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use PropTypes.shape here too?

]),
isDisabled: PropTypes.bool,
toggleButtonRef: PropTypes.func,
fullWidth: PropTypes.bool,
Expand Down Expand Up @@ -100,15 +103,21 @@ export class EuiComboBoxInput extends Component {
const {
label,
color,
onClick,
...rest
} = option;

const asPlainText = singleSelection && singleSelection.asPlainText;
Copy link
Contributor

@cjcenizal cjcenizal Aug 24, 2018

Choose a reason for hiding this comment

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

Here's how we can set asPlainText to default to true:

      // Default asPlainText to true if using singleSelection.
      const asPlainText = singleSelection && singleSelection.asPlainText !== false;

Note that this will be a breaking change for anyone who is depending upon the pill form so we'll need to update the CHANGELOG.md.


return (
<EuiComboBoxPill
option={option}
onClose={(isDisabled || singleSelection) ? null : onRemoveOption}
onClose={(isDisabled || singleSelection || onClick) ? null : onRemoveOption}
key={label.toLowerCase()}
color={color}
onClick={onClick}
onClickAriaLabel={onClick ? 'Change' : null}
asPlainText={asPlainText}
{...rest}
>
{label}
Expand Down Expand Up @@ -171,6 +180,8 @@ export class EuiComboBoxInput extends Component {

const wrapClasses = classNames('euiComboBox__inputWrap', {
'euiComboBox__inputWrap--fullWidth': fullWidth,
'euiComboBox__inputWrap--noWrap': singleSelection,
'euiComboBox__inputWrap-isClearable': onClear,
});

return (
Expand Down
31 changes: 17 additions & 14 deletions src/components/combo_box/combo_box_input/combo_box_pill.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React, {
Component,
} from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

import {
EuiBadge,
} from '../../badge';
import { EuiBadge } from '../../badge';

export class EuiComboBoxPill extends Component {
static propTypes = {
Expand All @@ -15,6 +11,7 @@ export class EuiComboBoxPill extends Component {
className: PropTypes.string,
color: PropTypes.string,
onClose: PropTypes.func,
asPlainText: PropTypes.bool,
};

static defaultProps = {
Expand All @@ -33,9 +30,16 @@ export class EuiComboBoxPill extends Component {
option, // eslint-disable-line no-unused-vars
onClose, // eslint-disable-line no-unused-vars
color,
asPlainText,
...rest
} = this.props;
const classes = classNames('euiComboBoxPill', className);
const classes = classNames(
'euiComboBoxPill',
{
'euiComboBoxPill--plainText': asPlainText,
},
className
);

if (onClose) {
return (
Expand All @@ -48,7 +52,7 @@ export class EuiComboBoxPill extends Component {
iconSide="right"
color={color}
closeButtonProps={{
tabIndex: '-1'
tabIndex: '-1',
}}
{...rest}
>
Expand All @@ -57,13 +61,12 @@ export class EuiComboBoxPill extends Component {
);
}

if (asPlainText) {
return <span className={classes}>{children}</span>;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this also pass ...rest ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Youp, I'll add it. Good catch.

}

return (
<EuiBadge
className={classes}
title={children}
color={color}
{...rest}
>
<EuiBadge className={classes} title={children} color={color} {...rest}>
{children}
</EuiBadge>
);
Expand Down