Skip to content

feat: Allow scientific notation in spinbox #2239 #2264

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions ui/src/spinbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,30 @@ export const
const [head, tail = ''] = val.split('.')
setVal(`${head}.${tail.slice(0, precision)}`)
}
else setVal(String(newValue))
return newValue
else {
// Check if the value is in scientific notation
if (isScientific) {
// If the value is in scientific notation, check if it's within the specified range
if (numericValue < 1e-4 || numericValue > 1e6) {
// If it's not within the range, transform the value into decimal
const decimalValue = scientificToDecimal(numericValue);
setVal(decimalValue);
return decimalValue;
}
} else {
// If the value is in decimal notation, check if it's within the specified range
if (numericValue < 1e-4 || numericValue > 1e6) {
// If it's not within the range, transform the value into scientific notation
const scientificValue = numericValue.toExponential();
setVal(scientificValue);
return scientificValue;
}
}

// If the value is within the specified range or not in scientific notation, keep the original value
setVal(val);
}
return newValue
}, [max, min, parseValue, precision]),
handleOnInput = React.useCallback((val: U) => {
wave.args[name] = val
Expand Down Expand Up @@ -148,4 +170,4 @@ export const
disabled={disabled}
/>
)
}
}