Skip to content

Relax type of CheckboxFieldProps["inputRef"] from RefObject to Ref #10319

Description

@jhbertra

Provide a general summary of the feature here

Currently CheckboxFieldProps["inputRef"] has type RefObject<HTMLInputElement | null>, which means that ref callbacks cannot be used. However, it should be fine to pass an arbitrary Ref<HTMLInputElement | null>, as ultimately it only gets consumed inside useCheckboxAria here, and mergeRefs accepts Array<Ref<T> | MutableRefObject<T> | null | undefined>.

Therefore, implementing this change should be as simple as relaxing the type in the prop interface, no code changes required.

🤔 Expected Behavior?

I should be able to pass a ref object or a ref callback to inputRef when creating a CheckboxField. If a ref callback is passed, it should behave as if passed to a regular input JSX element - receiving the input node on component mount and running any returned cleanup function on unmount.

😯 Current Behavior

The types claim can only pass a RefObject to inputRef. However, unsafely casing a ref callback to a ref object should work with the code as-is today (though this relies on assumptions about the implementation details that may break without warning, hence is not a good idea).

💁 Possible Solution

Change the type from RefObject to Ref.

🔦 Context

We are using the same pattern that ref callbacks were designed to improve - effect synchronization with dom node lifecycle. Our current workaround uses useRef + useEffect but this is less reliable, because there is no synchronization between when the ref gets assigned and when the effect fires.

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions