Skip to content

Commit

Permalink
[frontend] dont disable when value > limit (#6294)
Browse files Browse the repository at this point in the history
  • Loading branch information
frapuks committed Mar 12, 2024
1 parent beaac8f commit 698b5a3
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, FieldProps } from 'formik';
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useState } from 'react';
import { Grid, MenuItem, Select, SelectChangeEvent, Slider } from '@mui/material';
import SimpleTextField from './SimpleTextField';
import { SubscriptionFocus } from './Subscription';
Expand Down Expand Up @@ -59,6 +59,8 @@ const InputSliderField: FunctionComponent<InputSliderFieldProps & FieldProps> =
};
const currentLevel = buildScaleLevel(value, scale);

const [initialValue] = useState(value);

if (variant === 'edit') {
return (
<>
Expand All @@ -72,7 +74,7 @@ const InputSliderField: FunctionComponent<InputSliderFieldProps & FieldProps> =
label={label}
onSubmit={onSubmit}
onFocus={onFocus}
disabled={disabled || value > max}
disabled={disabled || initialValue > max}
helpertext={
<SubscriptionFocus context={editContext} fieldName={name} />
}
Expand All @@ -84,7 +86,7 @@ const InputSliderField: FunctionComponent<InputSliderFieldProps & FieldProps> =
labelId={name}
value={currentLevel.level.value?.toString() ?? ''}
onChange={updateFromSelect}
disabled={disabled || value > max}
disabled={disabled || initialValue > max}
sx={{ marginTop: 2 }} // to align field with the number input, that has a label
>
{marks.map((mark, i: number) => {
Expand All @@ -111,7 +113,7 @@ const InputSliderField: FunctionComponent<InputSliderFieldProps & FieldProps> =
valueLabelDisplay="off"
size="small"
valueLabelFormat={() => currentLevel.level.label}
disabled={disabled || value > max}
disabled={disabled || initialValue > max}
/>
</>
);
Expand Down

0 comments on commit 698b5a3

Please sign in to comment.