-
Notifications
You must be signed in to change notification settings - Fork 883
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
fix: remove trim from onchange event and trim the value onBlur (#4729) #4891
base: main
Are you sure you want to change the base?
Conversation
onChange={(event) => localValue.set(event.target.value)} | ||
onBlur={(event) => { | ||
localValue.set((event.target as HTMLInputElement).value.trim()); | ||
localValue.save; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
save is not invoked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do trimming inside of useLocalValue callback instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do trimming inside of useLocalValue callback instead
I tried this initially but the text was getting trimmed after a few milliseconds when we are typing.
screenrecord-2025-02-19_21-26-27.mp4
we could use something like the following
export a new function inside the useLocalvalue hook.
const finalSave = (value: Type) => {
localValueRef.current = value;
setRefresh((refresh) => refresh + 1);
save();
};
then run it on the onBlur event as follows, which would trim out the white space and also call the save function to sync the value on the server. what do you think @TrySound
<InputField
id={id}
/* Key is required, otherwise when label is undefined, previous value stayed */
key={selectedInstance.id}
placeholder={placeholder}
value={localValue.value}
onChange={(event) => localValue.set(event.target.value)}
onBlur={(event) =>
localValue.finalSave(
(event.target as HTMLInputElement).value.trim()
)
}
/>
a9d86fe
to
8785b79
Compare
@@ -175,6 +175,12 @@ export const useLocalValue = <Type,>( | |||
} | |||
}; | |||
|
|||
const finalSave = (value: Type) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't sound like great addition to the api, semantics with this are messy.
onBlur={localValue.save} | ||
onChange={(event) => localValue.set(event.target.value)} | ||
onBlur={(event) => | ||
localValue.finalSave( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TrySound maybe take over and see what's the best solution, because we are not getting anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to me it seemed like the initial version, where he was setting the trimmed value on blur and then calling save was a good call
Description
fixes issue #4729
the issues was happening since the value during onchange event had a trim in the end that removed the space from the end and beginning.
we removed the trim from onchange event and moved it to onBlur, so while typing we can enter space at the end and beginning, but when the element looses focus we trim the value.
Steps for reproduction
Code Review
Before requesting a review
Before merging
.env
file