Skip to content

Commit 35e5c51

Browse files
authored
Merge pull request #3651 from neos/bugfix/rangeeditor_with_float_values
BUGFIX: Allow float numbers in RangeEditor
2 parents 74f88b3 + c3ea19c commit 35e5c51

File tree

1 file changed

+6
-2
lines changed
  • packages/neos-ui-editors/src/Editors/Range

1 file changed

+6
-2
lines changed

packages/neos-ui-editors/src/Editors/Range/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class RangeEditor extends PureComponent {
4141
handleChange = event => {
4242
const {options} = this.props;
4343
const {target} = event;
44+
const useParseInt = (options.step || 1) % 1 === 0;
4445

45-
let value = parseInt(target.value, 10);
46+
let value = useParseInt ? parseInt(target.value, 10) : parseFloat(target.value, 10);
4647
if (isNaN(value)) {
4748
return;
4849
}
@@ -64,7 +65,10 @@ class RangeEditor extends PureComponent {
6465
const options = {...this.constructor.defaultProps.options, ...this.props.options};
6566
const {value, highlight} = this.props;
6667
const valueAsString = value === 0 ? '0' : (value || '');
67-
const styleWidth = Math.max(options.min.toString().length, options.max.toString().length) + 'ch';
68+
// Calculate the width of the input field based on the length of the min, max and step values
69+
const numLength = value => value.toString().length;
70+
const additionalStepLength = numLength(options.step) - 1;
71+
const styleWidth = Math.max(numLength(options.min), numLength(options.max)) + additionalStepLength + 'ch';
6872

6973
return (
7074
<div

0 commit comments

Comments
 (0)