Skip to content

Commit

Permalink
Pre-define already selected type for a new option (#402)
Browse files Browse the repository at this point in the history
* predefine option type and add invalid state for empty value

* use type of first option
  • Loading branch information
vitPinchuk authored May 31, 2024
1 parent a7d9d57 commit 651868e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/ElementOptionsEditor/ElementOptionsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const ElementOptionsEditor: React.FC<Props> = ({ options = [], onChange,
aria-label={TEST_IDS.formElementsEditor.fieldOptionType}
/>
</InlineField>
<InlineField label="Value" labelWidth={6} grow={true}>
<InlineField invalid={!option.value} label="Value" labelWidth={6} grow={true}>
<Input
placeholder={option.type === FormElementType.NUMBER ? 'number' : 'string'}
type={option.type === FormElementType.NUMBER ? 'number' : undefined}
Expand Down Expand Up @@ -255,6 +255,7 @@ export const ElementOptionsEditor: React.FC<Props> = ({ options = [], onChange,
onClick={() => {
const newOption = {
...FORM_ELEMENT_OPTION_DEFAULT,
type: !!options.length ? options[0].type : FORM_ELEMENT_OPTION_DEFAULT.type,
};

onChange(options.concat(newOption));
Expand Down

0 comments on commit 651868e

Please sign in to comment.