Skip to content

Commit

Permalink
ui v2: add end adornment support to text fields (#776)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschaller authored Dec 11, 2020
1 parent 27ecf5c commit ca43472
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from "react";
import SearchIcon from "@material-ui/icons/Search";
import type { Meta } from "@storybook/react";

import type { TextFieldProps } from "../text-field";
Expand Down Expand Up @@ -42,3 +43,10 @@ MultipleLines.args = {
multiline: true,
defaultValue: "This is\nan example\nof multiline content",
};

export const WithEndAdornment = Template.bind({});
WithEndAdornment.args = {
...Primary.args,
defaultValue: "Search",
endAdornment: <SearchIcon />,
};
38 changes: 33 additions & 5 deletions frontend/packages/core/src/Input/text-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {
InputProps as MuiInputProps,
StandardTextFieldProps as MuiStandardTextFieldProps,
} from "@material-ui/core";
import { TextField as MuiTextField } from "@material-ui/core";
import { IconButton as MuiIconButton, TextField as MuiTextField } from "@material-ui/core";
import ErrorIcon from "@material-ui/icons/Error";

const KEY_ENTER = 13;
Expand Down Expand Up @@ -42,7 +42,6 @@ const StyledTextField = styled(BaseTextField)({
border: "1px solid rgba(13, 16, 48, 0.38)",
borderRadius: "4px",
fontSize: "16px",
padding: "14px 16px",
},

"label + .MuiInput-formControl": {
Expand All @@ -51,14 +50,20 @@ const StyledTextField = styled(BaseTextField)({

".MuiInputBase-root.Mui-focused": {
borderColor: "#3548d4",
".MuiButtonBase-root": {
backgroundColor: "#3548D4",
"*": {
color: "#FFFFFF",
},
},
},

".MuiInputBase-root.Mui-disabled": {
backgroundColor: "rgba(13, 16, 48, 0.12)",
},

".MuiInput-input": {
padding: "0",
padding: "14px 16px",
height: "20px",
},

Expand Down Expand Up @@ -91,6 +96,25 @@ const StyledTextField = styled(BaseTextField)({
},
});

const IconButton = styled(MuiIconButton)({
borderRadius: "0",
backgroundColor: "#E7E7EA",
borderBottomRightRadius: "3px",
borderTopRightRadius: "3px",
"&:hover": {
backgroundColor: "#2D3DB4",
"*": {
color: "#FFFFFF",
},
},
"&:active": {
backgroundColor: "#2938A5",
"*": {
color: "#FFFFFF",
},
},
});

export interface TextFieldProps
extends Pick<
MuiStandardTextFieldProps,
Expand All @@ -111,7 +135,7 @@ export interface TextFieldProps
| "type"
| "value"
>,
Pick<MuiInputProps, "readOnly"> {
Pick<MuiInputProps, "readOnly" | "endAdornment"> {
onReturn?: () => void;
}

Expand All @@ -121,6 +145,7 @@ export const TextField = ({
error,
helperText,
readOnly,
endAdornment,
...props
}: TextFieldProps) => {
const onKeyDown = (
Expand Down Expand Up @@ -153,7 +178,10 @@ export const TextField = ({
onBlur={onChange}
error={error}
helperText={helpText}
InputProps={{ readOnly }}
InputProps={{
readOnly,
endAdornment: endAdornment && <IconButton type="submit">{endAdornment}</IconButton>,
}}
{...props}
/>
);
Expand Down

0 comments on commit ca43472

Please sign in to comment.