-
Notifications
You must be signed in to change notification settings - Fork 510
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1254 from rjackson/fix-safari-blanking-number-on-…
…decimals Fix Safari turning decimal number inputs to 0
- Loading branch information
Showing
6 changed files
with
66 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import type { IEditorCellProps } from "@src/components/fields/types"; | ||
import EditorCellTextField from "@src/components/Table/TableCell/EditorCellTextField"; | ||
|
||
export default function Number_(props: IEditorCellProps<number>) { | ||
export default function Number_(props: IEditorCellProps<number | string>) { | ||
return ( | ||
<EditorCellTextField | ||
{...(props as any)} | ||
InputProps={{ type: "number" }} | ||
onChange={(v) => props.onChange(Number(v))} | ||
onChange={(v) => { | ||
// Safari/Firefox gives us an empty string for invalid inputs, which includes inputs like "12." on the way to | ||
// typing "12.34". Number would cast these to 0 and replace the user's input to 0 whilst they're mid-way through | ||
// typing. We want to avoid that. | ||
const parsedValue = v === "" ? v : Number(v); | ||
props.onChange(parsedValue); | ||
}} | ||
onBlur={() => { | ||
// Cast to number when the user has finished editing | ||
props.onChange(Number(props.value)); | ||
props.onDirty(); | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters