feat: add a new parameter to trigger validation on setValue#38
feat: add a new parameter to trigger validation on setValue#38
Conversation
39151e6 to
97cdd3c
Compare
|
Hey Diego - I took a look at this and I think we're overcomplicating it with the boolean parameter approach. The real issue is architectural: The Root CauseWhen a user types in an element, it triggers That's the actual bug. Cleaner Solution: Dependency InjectionInstead of adding boolean params and global handler registries, we should just pass // In useBtRef.ts
type UseBtRefProps = {
btRef?: ForwardedRef<BTDateRef | BTRef>;
elementRef: RefObject<TextInput>;
id: string;
setElementValue: Dispatch<SetStateAction<string>>;
type?: ElementType;
onChange?: (value: string) => void; // NEW: Accept the onChange handler
};
export const useBtRef = ({
btRef,
elementRef,
id,
type,
setElementValue,
onChange, // NEW
}: UseBtRefProps) => {
useEffect(() => {
const valueSetter: ValueSetter = (val) => {
const formattedValue = valueFormatter(val);
// Update the display
setElementValue(formattedValue);
// Always trigger validation (just like user input does)
if (onChange) {
onChange(formattedValue);
}
};
const newBtRef = createBtRef({
id,
elementRef,
valueSetter,
type,
});
updateRef(btRef\!, newBtRef);
}, [btRef, elementRef, id, type, setElementValue, onChange]);
};Then in the element hooks (e.g., const { _onChange, _onBlur, _onFocus } = useUserEventHandlers({
// ... existing props
});
useBtRef({
btRef,
elementRef,
id,
setElementValue,
type,
onChange: _onChange, // NEW: Pass the handler directly
});Why This Is Better
The key insight: What do you think? Want me to pair on this refactor? |
97cdd3c to
5554d9d
Compare
5554d9d to
0a5cc7b
Compare
Description
Testing required outside of automated testing?
Screenshots (if appropriate):
Rollback / Rollforward Procedure
Reviewer Checklist