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

Make number slider more robust against weird input values #4758

Merged
merged 4 commits into from
Aug 10, 2020
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
import { Row, Col, Slider, InputNumber, Switch, Tooltip, Input, Icon, Select } from "antd";
import * as React from "react";
import _ from "lodash";

import type { Vector3, Vector6 } from "oxalis/constants";
import * as Utils from "libs/utils";
Expand Down Expand Up @@ -29,7 +30,11 @@ export class NumberSliderSetting extends React.PureComponent<NumberSliderSetting
};

render() {
const { value, label, max, min, step, onChange, disabled } = this.props;
const { value: originalValue, label, max, min, step, onChange, disabled } = this.props;

// Validate the provided value. If it's not valid, fallback to the midpoint between min and max.
const isValueValid = _.isNumber(originalValue) && originalValue >= min && originalValue <= max;
const value = isValueValid ? originalValue : Math.floor((min + max) / 2);
philippotto marked this conversation as resolved.
Show resolved Hide resolved

return (
<Row type="flex" align="middle">
Expand Down