Skip to content

Commit

Permalink
Merge pull request #159 from AppQuality/develop
Browse files Browse the repository at this point in the history
Add onChange event to DateInput component
  • Loading branch information
iacopolea authored Jan 5, 2024
2 parents 66c49ac + 43f07df commit 32427f5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/stories/DateInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import {
Datepicker as MobiScrollDatePicker,
localeEn,
Expand Down Expand Up @@ -60,6 +61,7 @@ export const DateInput = ({
} = {},
}: DatepickerProps) => {
let currentLocale = localeEn;
const ref = React.useRef<HTMLInputElement>(null);
if (locale === "it") currentLocale = localeIt;
if (locale === "es") currentLocale = localeEs;
const [openPicker, setOpenPicker] = useState(false);
Expand All @@ -73,6 +75,10 @@ export const DateInput = ({
};
const onDatePick = (v: { value: Date; valueText: string }) => {
setInputValue(v.valueText);
if (ref.current) {
ref.current.value = v.valueText;
ref.current.dispatchEvent(new Event("input", { bubbles: true }));
}
onClose();
};
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -86,8 +92,9 @@ export const DateInput = ({
name={name}
type="text"
value={inputValue}
onChange={handleInputChange}
onInput={handleInputChange}
placeholder={placeholder}
ref={ref}
{...inputProps}
/>
<MobiScrollDatePicker
Expand Down

0 comments on commit 32427f5

Please sign in to comment.