1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Add data-test-id prop to TextField component (#13973)

The `data-test-id` prop has been added to `TextField`. This prop allows
selecting this component more easily from e2e and unit tests. This is
required for a subsequent PR that includes a text field that cannot be
selected for by placeholder or contents or label (any of which would
have been preferable).
This commit is contained in:
Mark Stacey 2022-03-15 20:42:37 -02:30 committed by GitHub
parent cd28e64539
commit c7fabbff87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -204,6 +204,7 @@ const themeToInputProps = {
};
const TextField = ({
'data-testid': dataTestId,
error,
classes,
theme,
@ -228,7 +229,7 @@ const TextField = ({
autoComplete,
});
if (onPaste) {
if (onPaste || dataTestId) {
if (!inputProps.InputProps) {
inputProps.InputProps = {};
}
@ -236,6 +237,7 @@ const TextField = ({
inputProps.InputProps.inputProps = {};
}
inputProps.InputProps.inputProps.onPaste = onPaste;
inputProps.InputProps.inputProps['data-testid'] = dataTestId;
}
return (
@ -255,6 +257,10 @@ TextField.defaultProps = {
};
TextField.propTypes = {
/**
* A test ID that gets set on the input element
*/
'data-testid': PropTypes.string,
/**
* Show error message
*/

View File

@ -3,7 +3,6 @@
exports[`SearchableItemList renders the component with initial props 1`] = `
<div
class="MuiFormControl-root MuiTextField-root searchable-item-list__search MuiFormControl-fullWidth"
data-testid="search-list-items"
>
<div
class="MuiInputBase-root MuiInput-root TextField-inputRoot-12 MuiInputBase-fullWidth MuiInput-fullWidth Mui-focused Mui-focused TextField-inputFocused-11 MuiInputBase-formControl MuiInput-formControl MuiInputBase-adornedStart"
@ -23,6 +22,7 @@ exports[`SearchableItemList renders the component with initial props 1`] = `
aria-invalid="false"
autocomplete="off"
class="MuiInputBase-input MuiInput-input MuiInputBase-inputAdornedStart"
data-testid="search-list-items"
dir="auto"
type="text"
value=""