-
-
Notifications
You must be signed in to change notification settings - Fork 109
refactor: add opts and logic to allow submit on enter only under cuesheet line cell for time inputs #1945
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
refactor: add opts and logic to allow submit on enter only under cuesheet line cell for time inputs #1945
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ export default function useReactiveTextInput( | |
| onCancelUpdate?: () => void; | ||
| allowSubmitSameValue?: boolean; | ||
| allowKeyboardNavigation?: boolean; | ||
| allowSubmitOnEnterOnly?: boolean; | ||
| }, | ||
| ): UseReactiveTextInputReturn { | ||
| const [text, setText] = useState<string>(initialText); | ||
|
|
@@ -50,10 +51,17 @@ export default function useReactiveTextInput( | |
| * @param {string} valueToSubmit | ||
| */ | ||
| const handleSubmit = useCallback( | ||
| (valueToSubmit: string) => { | ||
| (valueToSubmit: string, triggeredKey?: string) => { | ||
| // No need to update if it hasn't changed | ||
| if (valueToSubmit === initialText && !options?.allowSubmitSameValue) { | ||
| options?.onCancelUpdate?.(); | ||
| } else if ( | ||
| valueToSubmit === initialText && | ||
| options?.allowSubmitOnEnterOnly && | ||
| triggeredKey !== 'Enter' && | ||
| triggeredKey !== 'mod + Enter' | ||
| ) { | ||
| options?.onCancelUpdate?.(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seams that we don't provide a function here witch result is potentially stale data
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think this was being prevented with the check for initial value and the new value before. if there's a change in the value, it would not enter this statement block even if we were to pass in the cancel callback, it should submit the value in case there's a change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i can think of 2 ways to handle this.
do you have any other suggestions on this? @alex-Arc
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first another question, what do we mean by
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suppose this flag is false, we're accepting submission on Escape and Tab as well. The The scenario would be that the user is active on a time input and they tab to the next input without changing any value, it would still submit. We want to allow a submission only on the enter key and not allow tab or escape to enter So we pass in the flag of Do let me know if I can be more clear on a specific part
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good I understood correctly,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, but the edge case you mentioned where if the user has changed the value and then they tab, the value won't be submitted is not what we want. in any case that the value changes, we want it to submit
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then looking further back into it, is the issue not that we have some formatting in the time filed that automatically get a value when you tab into them?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the issue is that when the value doesn't change on time inputs and the user tabs / escapes on the active time field, there's a submission of the value that happens i did try scoping the issue to the time field inputs but the issue is that there's a prop of basically, what we need to do is:
the reason this logic above isn't satisfied by the happy to take in suggestions or improvements on the name or the overall logic |
||
| } else { | ||
| const cleanVal = valueToSubmit.trim(); | ||
| submitCallback(cleanVal); | ||
|
|
@@ -105,7 +113,7 @@ export default function useReactiveTextInput( | |
| 'Enter', | ||
| () => { | ||
| isKeyboardSubmitting.current = true; | ||
| handleSubmit(text); | ||
| handleSubmit(text, 'Enter'); | ||
| // clear flag after blur has been processed | ||
| setTimeout(() => { | ||
| isKeyboardSubmitting.current = false; | ||
|
|
@@ -119,7 +127,7 @@ export default function useReactiveTextInput( | |
| 'mod + Enter', | ||
| () => { | ||
| isKeyboardSubmitting.current = true; | ||
| handleSubmit(text); | ||
| handleSubmit(text, 'mod + Enter'); | ||
| // clear flag after blur has been processed | ||
| setTimeout(() => { | ||
| isKeyboardSubmitting.current = false; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.