-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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: Improve Usability of Adding Options via Return Key for Multi-Select Field #7450
fix: Improve Usability of Adding Options via Return Key for Multi-Select Field #7450
Conversation
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.
PR Summary
This PR addresses issue #6602 by improving the usability of adding options via the Return key for multi-select fields. The changes focus on enhancing the text selection behavior when a new option is added.
- Implemented
forwardRef
inTextInput
component to allow parent components to access the input element directly - Added
hasFocused
state andhandleInputRef
callback inSettingsDataModelFieldSelectFormOptionRow
to manage focus and text selection - Modified
TextInput
to useuseCombinedRefs
hook, combining the forwarded ref with the internalinputRef
- Updated
SettingsDataModelFieldSelectFormOptionRow
to pass aref
prop toTextInput
, enabling automatic text selection for new options
2 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings
@@ -88,6 +89,17 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({ | |||
onInputEnter?.(); | |||
}; | |||
|
|||
const handleInputRef = useCallback( | |||
(node: HTMLInputElement | null) => { | |||
if (Boolean(node) && !hasFocused && Boolean(focused)) { |
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.
style: consider using node && !hasFocused && focused
instead of Boolean(node) && !hasFocused && Boolean(focused)
for consistency and readability
Hi @FelixMalfait , thank you for reviewing my previous PR. Please let me know if the current way is the right approach. Otherwise, I'm happy to take another direction. Thank you! |
Hi @nganphan123, the way you have chosen seems quite hacky to me:
I'm investigating a bit to give you more precise hints |
Hi, The difficulty here was to work at the right abstraction layer. We wanted the selection to happen on new select option row, so the component The intent was "the new option row should be selected and focused on mount" so I divided this into other intents :
Then in the option row .map, we just tell each row if it's a new row or not. |
Awarding nganphan123: 150 points 🕹️ Well done! Check out your new contribution on oss.gg/nganphan123 |
Thanks @nganphan123 for your contribution! |
…ect Field (twentyhq#7450) Fixes twentyhq#6602 This is the approach that I followed based on these comments twentyhq#6602 (comment), twentyhq#6602 (comment) - Create forward ref in `<TextInput>` component - Create ref to select text in parent component `<SettingsDataModelFieldSelectFormOptionRow>` and pass it to `<TextInput>` --------- Co-authored-by: Lucas Bordeau <[email protected]>
Fixes #6602
This is the approach that I followed based on these comments #6602 (comment), #6602 (comment)
<TextInput>
component<SettingsDataModelFieldSelectFormOptionRow>
and pass it to<TextInput>