Repository navigation
Is there a way to control the calendar open/close event? #4993
Unanswered
nicolas-c-dev
asked this question in
Q&A
Replies: 1 comment
|
Use import { forwardRef, useState } from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
const InputWithButton = forwardRef(function InputWithButton(
{ onClick, ...inputProps },
ref,
) {
return (
<span>
<input {...inputProps} ref={ref} />
<button type="button" onClick={onClick} aria-label="Open calendar">
📅
</button>
</span>
);
});
export default function Example() {
const [date, setDate] = useState(null);
return (
<DatePicker
selected={date}
onChange={setDate}
preventOpenOnFocus
customInput={<InputWithButton />}
/>
);
}The text input retains the injected value, change, blur, keyboard handlers, and ref, but not the opening click handler. The button remains keyboard-activatable and avoids submitting a surrounding form.
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Hi, i need to know if there is a function to control when calendar open or closes cause they ask me to open calendar only when click on icon button, not when click or focus the input. Thanks
All reactions