Skip to content

Commit

Permalink
Add support for decimal numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
vantezzen committed Aug 6, 2023
1 parent be57451 commit 051e499
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/shared/components/speedSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SpeedSetting = ({
const value = config.current[name] as number
const isCustomValue = config.current[`${name}_is_custom` as IsCustomKeys]
const [isOpen, setIsOpen] = React.useState(false)
const [tempValue, setTempValue] = React.useState<string | null>(null)

let selector
if (isCustomValue) {
Expand All @@ -37,9 +38,15 @@ const SpeedSetting = ({
<div className="custom-value-container">
<input
type="number"
value={value}
value={tempValue ?? value}
onChange={(evt) => {
config.current[name] = parseInt(evt.target.value)
// Handle incomplete numbers (e.g. "12,")
if (!/[0-9]$/.test(evt.target.value)) {
setTempValue(evt.target.value)
}

config.current[name] = parseFloat(evt.target.value)
setTempValue(null)

if (config.environment === StateEnvironment.Popup) {
window.sa_event(`speed_${name}_custom_${evt.target.value}`)
Expand All @@ -49,7 +56,7 @@ const SpeedSetting = ({
}
}}
step={0.1}
min={0.0625}
min={0.06}
max={16}
/>
<button
Expand Down

0 comments on commit 051e499

Please sign in to comment.