Skip to content

Commit

Permalink
Add an invalid state to EuiSuperSelect (#1804)
Browse files Browse the repository at this point in the history
  • Loading branch information
snide authored Apr 8, 2019
1 parent 68594fb commit 77b4f88
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Converted `EuiTableHeaderMobile` to TS ([#1786](https://github.com/elastic/eui/pull/1786))
- Added `menuLeft` and `menuRight` icons ([#1797](https://github.com/elastic/eui/pull/1797))
- Updated EuiNavDrawer’s collapse/expand button to use `menuLeft` and `menuRight` icons ([#1797](https://github.com/elastic/eui/pull/1797))
- Added `isInvalid` prop to `EuiSuperSelect` ([#1804](https://github.com/elastic/eui/pull/1804))
- Added `cut` glyph to `EuiIcon` ([#1802](https://github.com/elastic/eui/pull/1802))

## [`9.8.0`](https://github.com/elastic/eui/tree/v9.8.0)
Expand Down
9 changes: 9 additions & 0 deletions src-docs/src/views/super_select/super_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ export default class extends Component {

<EuiSpacer size="m" />

<EuiSuperSelect
options={this.options}
valueOfSelected={this.state.value}
onChange={this.onChange}
isInvalid
/>

<EuiSpacer size="m" />

<EuiSuperSelect
options={this.options}
valueOfSelected={this.state.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
data-test-subj="superSelect"
fullWidth={false}
hasDividers={false}
isInvalid={false}
onChange={[Function]}
options={
Array [
Expand All @@ -488,6 +489,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
compressed={false}
data-test-subj="superSelect"
fullWidth={false}
isInvalid={false}
isLoading={false}
onChange={[Function]}
onClick={[Function]}
Expand Down Expand Up @@ -538,6 +540,7 @@ exports[`EuiSuperSelect props more props are propogated to each option 2`] = `
compressed={false}
data-test-subj="superSelect"
fullWidth={false}
isInvalid={false}
isLoading={false}
onChange={[Function]}
onClick={[Function]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,65 @@ Array [
]
`;

exports[`EuiSuperSelectControl props isInvalid is rendered 1`] = `
Array [
<input
type="hidden"
value=""
/>,
<div
class="euiFormControlLayout"
>
<div
class="euiFormControlLayout__childrenWrapper"
>
<span
class="euiScreenReaderOnly"
id="generated-id"
>
Select an option: , is selected
</span>
<button
aria-haspopup="true"
aria-labelledby="undefined generated-id"
class="euiSuperSelectControl euiSuperSelectControl-isInvalid"
role="option"
type="button"
/>
<div
class="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"
>
<span
class="euiFormControlLayoutCustomIcon"
>
<svg
aria-hidden="true"
class="euiIcon euiIcon--medium euiFormControlLayoutCustomIcon__icon"
focusable="false"
height="16"
viewBox="0 0 16 16"
width="16"
xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
>
<defs>
<path
d="M13.069 5.157L8.384 9.768a.546.546 0 0 1-.768 0L2.93 5.158a.552.552 0 0 0-.771 0 .53.53 0 0 0 0 .759l4.684 4.61c.641.631 1.672.63 2.312 0l4.684-4.61a.53.53 0 0 0 0-.76.552.552 0 0 0-.771 0z"
id="arrow_down-a"
/>
</defs>
<use
fill-rule="nonzero"
href="#arrow_down-a"
/>
</svg>
</span>
</div>
</div>
</div>,
]
`;

exports[`EuiSuperSelectControl props isLoading is rendered 1`] = `
Array [
<input
Expand Down
4 changes: 4 additions & 0 deletions src/components/form/super_select/_super_select_control.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
text-overflow: ellipsis;
white-space: nowrap;

&-isInvalid {
@include euiFormControlInvalidStyle;
}

&--compressed {
line-height: $euiFormControlCompressedHeight; /* 2 */
padding-top: 0; /* 2 */
Expand Down
7 changes: 7 additions & 0 deletions src/components/form/super_select/super_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export class EuiSuperSelect extends Component {
valueOfSelected,
onChange,
isOpen,
isInvalid,
hasDividers,
itemClassName,
itemLayoutAlign,
Expand Down Expand Up @@ -199,6 +200,7 @@ export class EuiSuperSelect extends Component {
onKeyDown={this.onSelectKeyDown}
className={buttonClasses}
fullWidth={fullWidth}
isInvalid={isInvalid}
{...rest}
/>
);
Expand Down Expand Up @@ -302,6 +304,10 @@ EuiSuperSelect.propTypes = {
* Make it wide
*/
fullWidth: PropTypes.bool,
/**
* Provides invalid styling
*/
isInvalid: PropTypes.bool,
/**
* Make it short
*/
Expand All @@ -316,5 +322,6 @@ EuiSuperSelect.defaultProps = {
hasDividers: false,
fullWidth: false,
compressed: false,
isInvalid: false,
options: [],
};
3 changes: 3 additions & 0 deletions src/components/form/super_select/super_select_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const EuiSuperSelectControl = ({
name,
fullWidth,
isLoading,
isInvalid,
defaultValue,
compressed,
value,
Expand All @@ -27,6 +28,7 @@ export const EuiSuperSelectControl = ({
'euiSuperSelectControl--fullWidth': fullWidth,
'euiSuperSelectControl--compressed': compressed,
'euiSuperSelectControl-isLoading': isLoading,
'euiSuperSelectControl-isInvalid': isInvalid,
},
className
);
Expand Down Expand Up @@ -118,5 +120,6 @@ EuiSuperSelectControl.defaultProps = {
options: [],
fullWidth: false,
isLoading: false,
isInvalid: false,
compressed: false,
};
9 changes: 9 additions & 0 deletions src/components/form/super_select/super_select_control.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ describe('EuiSuperSelectControl', () => {
.toMatchSnapshot();
});

test('isInvalid is rendered', () => {
const component = render(
<EuiSuperSelectControl isInvalid/>
);

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

test('disabled options are rendered', () => {
const component = render(
<EuiSuperSelectControl
Expand Down

0 comments on commit 77b4f88

Please sign in to comment.