Skip to content
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

Add onChange event to DateInput component #159

Merged
merged 1 commit into from
Jan 5, 2024
Merged
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
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
Loading