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

Added prepend and append support for EuiFieldPassword #3122

Merged
merged 4 commits into from
Mar 19, 2020
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
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