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

Allow TextField to receive min and max attributes #10656

Merged
merged 1 commit into from
Mar 16, 2021
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
18 changes: 18 additions & 0 deletions ui/app/components/ui/text-field/text-field.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ const getMaterialThemeInputProps = ({
dir,
classes: { materialLabel, materialFocused, materialError, materialUnderline },
startAdornment,
min,
max,
}) => ({
InputLabelProps: {
classes: {
Expand All @@ -103,6 +105,8 @@ const getMaterialThemeInputProps = ({
},
inputProps: {
dir,
min,
max,
},
},
});
Expand All @@ -116,6 +120,8 @@ const getMaterialWhitePaddedThemeInputProps = ({
materialWhitePaddedUnderline,
},
startAdornment,
min,
max,
}) => ({
InputProps: {
startAdornment,
Expand All @@ -127,6 +133,8 @@ const getMaterialWhitePaddedThemeInputProps = ({
},
inputProps: {
dir,
min,
max,
},
},
});
Expand All @@ -145,6 +153,8 @@ const getBorderedThemeInputProps = ({
},
largeLabel,
startAdornment,
min,
max,
}) => ({
InputLabelProps: {
shrink: true,
Expand All @@ -165,6 +175,8 @@ const getBorderedThemeInputProps = ({
},
inputProps: {
dir,
min,
max,
},
},
});
Expand All @@ -182,13 +194,17 @@ const TextField = ({
startAdornment,
largeLabel,
dir,
min,
max,
...textFieldProps
}) => {
const inputProps = themeToInputProps[theme]({
classes,
startAdornment,
largeLabel,
dir,
min,
max,
});

return (
Expand All @@ -214,6 +230,8 @@ TextField.propTypes = {
theme: PropTypes.oneOf(['bordered', 'material', 'material-white-padded']),
startAdornment: PropTypes.element,
largeLabel: PropTypes.bool,
min: PropTypes.number,
max: PropTypes.number,
};

export default withStyles(styles)(TextField);
9 changes: 7 additions & 2 deletions ui/app/pages/add-token/add-token.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import TokenSearch from './token-search';

const emptyAddr = '0x0000000000000000000000000000000000000000';

const MIN_DECIMAL_VALUE = 0;
const MAX_DECIMAL_VALUE = 36;

class AddToken extends Component {
static contextTypes = {
t: PropTypes.func,
Expand Down Expand Up @@ -211,8 +214,8 @@ class AddToken extends Component {
const validDecimals =
customDecimals !== null &&
customDecimals !== '' &&
customDecimals >= 0 &&
customDecimals <= 36;
customDecimals >= MIN_DECIMAL_VALUE &&
customDecimals <= MAX_DECIMAL_VALUE;
let customDecimalsError = null;

if (!validDecimals) {
Expand Down Expand Up @@ -282,6 +285,8 @@ class AddToken extends Component {
fullWidth
margin="normal"
disabled={autoFilled}
min={MIN_DECIMAL_VALUE}
max={MAX_DECIMAL_VALUE}
/>
</div>
);
Expand Down