Skip to content

Commit

Permalink
Fixed datetime pickers
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Sep 3, 2024
1 parent c0b5ad1 commit 22e0721
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion library/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@irontec/ivoz-ui",
"version": "1.4.4",
"version": "1.4.5",
"description": "UI library used in ivozprovider",
"license": "GPL-3.0",
"main": "index.js",
Expand Down
17 changes: 11 additions & 6 deletions library/src/services/form/Field/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
OutlinedInputProps,
} from '@mui/material';
import { StyledHelpTextTooltip } from '../Shared/HelpText.styles';
import { KeyboardEventHandler } from 'react';
import { KeyboardEventHandler, useEffect, useState } from 'react';

export type TextFieldProps = MuiTextFieldProps & {
hasChanged: boolean;
Expand Down Expand Up @@ -49,6 +49,14 @@ export const TextField = (props: TextFieldProps) => {
className += ' changed';
}

const [inputValue, setInputValue] = useState(value);
useEffect(() => {
if (!value) {
return;
}
setInputValue(value);
}, [value]);

const labelId = `${name}-label`;
const maxRows = multiline ? 6 : undefined;

Expand All @@ -71,11 +79,8 @@ export const TextField = (props: TextFieldProps) => {
}

passThroughProps.onChange = (event) => {
const { target } = event;

if (type === 'datetime-local') {
const fixedDate = fixDateTime(target.value);
event.target = { ...target, ...{ value: fixedDate } };
setInputValue(fixDateTime(event.target.value));
}

if (onChange) {
Expand Down Expand Up @@ -116,7 +121,7 @@ export const TextField = (props: TextFieldProps) => {
maxRows={maxRows}
placeholder={placeholder}
defaultValue={defaultValue}
value={value}
value={inputValue}
disabled={disabled}
onBlur={onBlur}
error={error}
Expand Down

0 comments on commit 22e0721

Please sign in to comment.