Skip to content

Commit

Permalink
Added prepend and append support for EuiFieldPassword (#3122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashikmeerankutty authored Mar 19, 2020
1 parent 7e70683 commit a6b9fe4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

- Added `prepend` and `append` ability to `EuiFieldPassword` ([#3122](https://github.com/elastic/eui/pull/3122))
- Added `Enter` key press functionality to `EuiSuperDatePicker` ([#3048](https://github.com/elastic/eui/pull/3048))

**Bug Fixes**
Expand Down
2 changes: 1 addition & 1 deletion src-docs/src/views/form_controls/field_password.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class extends Component {
render() {
return (
/* DisplayToggles wrapper for Docs only */
<DisplayToggles>
<DisplayToggles canAppend canPrepend>
<EuiFieldPassword
placeholder="Placeholder text"
value={this.state.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,21 @@ exports[`EuiFieldPassword props isLoading is rendered 1`] = `
</eui-validatable-control>
</eui-form-control-layout>
`;

exports[`EuiFieldPassword props prepend and append is rendered 1`] = `
<eui-form-control-layout
append="String"
compressed="false"
fullwidth="false"
icon="lock"
isloading="false"
prepend="String"
>
<eui-validatable-control>
<input
class="euiFieldPassword euiFieldPassword--inGroup"
type="password"
/>
</eui-validatable-control>
</eui-form-control-layout>
`;
8 changes: 8 additions & 0 deletions src/components/form/field_password/field_password.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,13 @@ describe('EuiFieldPassword', () => {

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

test('prepend and append is rendered', () => {
const component = render(
<EuiFieldPassword prepend="String" append="String" />
);

expect(component).toMatchSnapshot();
});
});
});
24 changes: 22 additions & 2 deletions src/components/form/field_password/field_password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import React, { InputHTMLAttributes, Ref, FunctionComponent } from 'react';
import { CommonProps } from '../../common';
import classNames from 'classnames';

import { EuiFormControlLayout } from '../form_control_layout';
import {
EuiFormControlLayout,
EuiFormControlLayoutProps,
} from '../form_control_layout';

import { EuiValidatableControl } from '../validatable_control';

Expand All @@ -13,6 +16,18 @@ export type EuiFieldPasswordProps = InputHTMLAttributes<HTMLInputElement> &
isLoading?: boolean;
compressed?: boolean;
inputRef?: Ref<HTMLInputElement>;

/**
* Creates an input group with element(s) coming before input.
* `string` | `ReactElement` or an array of these
*/
prepend?: EuiFormControlLayoutProps['prepend'];

/**
* Creates an input group with element(s) coming after input.
* `string` | `ReactElement` or an array of these
*/
append?: EuiFormControlLayoutProps['append'];
};

export const EuiFieldPassword: FunctionComponent<EuiFieldPasswordProps> = ({
Expand All @@ -26,6 +41,8 @@ export const EuiFieldPassword: FunctionComponent<EuiFieldPasswordProps> = ({
isLoading,
compressed,
inputRef,
prepend,
append,
...rest
}) => {
const classes = classNames(
Expand All @@ -34,6 +51,7 @@ export const EuiFieldPassword: FunctionComponent<EuiFieldPasswordProps> = ({
'euiFieldPassword--fullWidth': fullWidth,
'euiFieldPassword--compressed': compressed,
'euiFieldPassword-isLoading': isLoading,
'euiFieldPassword--inGroup': prepend || append,
},
className
);
Expand All @@ -43,7 +61,9 @@ export const EuiFieldPassword: FunctionComponent<EuiFieldPasswordProps> = ({
icon="lock"
fullWidth={fullWidth}
isLoading={isLoading}
compressed={compressed}>
compressed={compressed}
prepend={prepend}
append={append}>
<EuiValidatableControl isInvalid={isInvalid}>
<input
type="password"
Expand Down

0 comments on commit a6b9fe4

Please sign in to comment.