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).
feature/default_network_editable
Mark Stacey 3 years ago
parent 1eecc59969
commit 851f9b30b4
  1. 8
      ui/components/ui/text-field/text-field.component.js
  2. 2
      ui/pages/swaps/searchable-item-list/__snapshots__/searchable-item-list.test.js.snap

@ -194,6 +194,7 @@ const themeToInputProps = {
};
const TextField = ({
'data-testid': dataTestId,
error,
classes,
theme,
@ -216,7 +217,7 @@ const TextField = ({
autoComplete,
});
if (onPaste) {
if (onPaste || dataTestId) {
if (!inputProps.InputProps) {
inputProps.InputProps = {};
}
@ -224,6 +225,7 @@ const TextField = ({
inputProps.InputProps.inputProps = {};
}
inputProps.InputProps.inputProps.onPaste = onPaste;
inputProps.InputProps.inputProps['data-testid'] = dataTestId;
}
return (
@ -243,6 +245,10 @@ TextField.defaultProps = {
};
TextField.propTypes = {
/**
* A test ID that gets set on the input element
*/
'data-testid': PropTypes.string,
/**
* Show error message
*/

@ -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=""

Loading…
Cancel
Save