Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/metal-chairs-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/elements": patch
---

Ensure updated provided values to controlled inputs are sent to the machine
14 changes: 7 additions & 7 deletions packages/elements/src/react/common/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ const useField = ({ name }: Partial<Pick<FieldDetails, 'name'>>) => {

const useInput = ({
name: inputName,
value: initialValue,
value: providedValue,
type: inputType,
onChange: onChangeProp,
onBlur: onBlurProp,
Expand Down Expand Up @@ -265,7 +265,7 @@ const useInput = ({
return;
}

ref.send({ type: 'FIELD.ADD', field: { name, value: initialValue } });
ref.send({ type: 'FIELD.ADD', field: { name, value: providedValue } });

return () => ref.send({ type: 'FIELD.REMOVE', field: { name } });
}, [ref]); // eslint-disable-line react-hooks/exhaustive-deps
Expand All @@ -274,15 +274,15 @@ const useInput = ({
const onChange = React.useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => {
onChangeProp?.(event);
if (!name || initialValue) {
if (!name) {
return;
}
ref.send({ type: 'FIELD.UPDATE', field: { name, value: event.target.value } });
if (shouldValidatePassword) {
validatePassword(event.target.value);
}
},
[ref, name, onChangeProp, initialValue, shouldValidatePassword, validatePassword],
[ref, name, onChangeProp, shouldValidatePassword, validatePassword],
);

const onBlur = React.useCallback(
Expand All @@ -306,11 +306,11 @@ const useInput = ({
);

React.useEffect(() => {
if (!initialValue || !name) {
if (!name) {
return;
}
ref.send({ type: 'FIELD.UPDATE', field: { name, value: initialValue } });
}, [name, ref, initialValue]);
ref.send({ type: 'FIELD.UPDATE', field: { name, value: providedValue } });
}, [name, ref, providedValue]);

// TODO: Implement clerk-js utils
const shouldBeHidden = false;
Expand Down