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

React Final Form callbacks are incompatible with date components #8

Closed
vvasin opened this issue Aug 22, 2023 · 1 comment
Closed

React Final Form callbacks are incompatible with date components #8

vvasin opened this issue Aug 22, 2023 · 1 comment

Comments

@vvasin
Copy link

vvasin commented Aug 22, 2023

The event callbacks from the FieldInputProps of React Final Form library are supposed to work with event targets of HTMLElement subtypes. By default all the date components expect event callbacks with targets of Element subtypes, which is more general. Therefore, we can't use the input callbacks out of box like this:

<Field ...>
    {({input}) => (
        <DatePicker onFocus={input.onFocus} ... />
    )}
</Field>

We have to wrap the callbacks instead:

const handleFocus = useCallback<Required<DatePickerProps>['onFocus']>(
    (event) => {
        if (event.target instanceof HTMLElement) {
            input.onFocus(event as React.FocusEvent<HTMLElement>);
        }
    },
    [onBlur],
);

It seems unnecessary, since the date components are supposed to work using HTML elements, I believe.

@ValeraS
Copy link
Contributor

ValeraS commented Feb 26, 2024

fixed in #54

@ValeraS ValeraS closed this as completed Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants