Skip to content
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

Merged
merged 8 commits into from
Oct 7, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from '@emotion/styled';
import { DropResult } from '@hello-pangea/dnd';
import { useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { IconPlus } from 'twenty-ui';
import { z } from 'zod';
Expand Down Expand Up @@ -79,7 +78,6 @@ const StyledButton = styled(LightButton)`
export const SettingsDataModelFieldSelectForm = ({
fieldMetadataItem,
}: SettingsDataModelFieldSelectFormProps) => {
const [focusedOptionId, setFocusedOptionId] = useState('');
const { initialDefaultValue, initialOptions } =
useSelectSettingsFormInitialValues({ fieldMetadataItem });

Expand Down Expand Up @@ -190,10 +188,6 @@ export const SettingsDataModelFieldSelectForm = ({
const newOptions = getOptionsWithNewOption();

setFormValue('options', newOptions);

const lastOptionId = newOptions[newOptions.length - 1].id;

setFocusedOptionId(lastOptionId);
};

return (
Expand Down Expand Up @@ -227,7 +221,7 @@ export const SettingsDataModelFieldSelectForm = ({
<SettingsDataModelFieldSelectFormOptionRow
key={option.id}
option={option}
focused={focusedOptionId === option.id}
isNewRow={index === options.length - 1}
onChange={(nextOption) => {
const nextOptions = toSpliced(
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SettingsDataModelFieldSelectFormOptionRowProps = {
onRemoveAsDefault?: () => void;
onInputEnter?: () => void;
option: FieldMetadataItemOption;
focused?: boolean;
isNewRow?: boolean;
};

const StyledRow = styled.div`
Expand Down Expand Up @@ -67,7 +67,7 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
onRemoveAsDefault,
onInputEnter,
option,
focused,
isNewRow,
}: SettingsDataModelFieldSelectFormOptionRowProps) => {
const theme = useTheme();

Expand Down Expand Up @@ -129,10 +129,11 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
value: getOptionValueFromLabel(label),
})
}
focused={focused}
RightIcon={isDefault ? IconCheck : undefined}
maxLength={OPTION_VALUE_MAXIMUM_LENGTH}
onInputEnter={handleInputEnter}
autoFocusOnMount={isNewRow}
autoSelectOnMount={isNewRow}
/>
<Dropdown
dropdownId={dropdownIds.actions}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { H2Title } from 'twenty-ui';
import { Section } from '@/ui/layout/section/components/Section';
import { TextInput } from '@/ui/input/components/TextInput';
import { ServerlessFunctionNewFormValues } from '@/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState';
import { TextArea } from '@/ui/input/components/TextArea';
import { TextInput } from '@/ui/input/components/TextInput';
import { Section } from '@/ui/layout/section/components/Section';
import styled from '@emotion/styled';
import { ServerlessFunctionNewFormValues } from '@/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState';
import { H2Title } from 'twenty-ui';

const StyledInputsContainer = styled.div`
display: flex;
Expand All @@ -25,7 +25,7 @@ export const SettingsServerlessFunctionNewForm = ({
<TextInput
placeholder="Name"
fullWidth
focused
autoFocusOnMount
value={formValues.name}
onChange={onChange('name')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export type TextInputProps = TextInputV2ComponentProps & {
disableHotkeys?: boolean;
onInputEnter?: () => void;
dataTestId?: string;
focused?: boolean;
autoFocusOnMount?: boolean;
autoSelectOnMount?: boolean;
};

export const TextInput = ({
onFocus,
onBlur,
onInputEnter,
disableHotkeys = false,
focused,
autoFocusOnMount,
autoSelectOnMount,
dataTestId,
...props
}: TextInputProps) => {
Expand All @@ -31,11 +33,17 @@ export const TextInput = ({
const [isFocused, setIsFocused] = useState(false);

useEffect(() => {
if (focused === true) {
if (autoFocusOnMount === true) {
inputRef.current?.focus();
setIsFocused(true);
}
}, [focused]);
}, [autoFocusOnMount]);

useEffect(() => {
if (autoSelectOnMount === true) {
inputRef.current?.select();
}
}, [autoSelectOnMount]);

const {
goBackToPreviousHotkeyScope,
Expand Down
Loading