Skip to content

Commit

Permalink
Fix(TDS-7331/forms): Select field being re-created instead of updated (
Browse files Browse the repository at this point in the history
  • Loading branch information
yyanwang authored Apr 24, 2024
1 parent f546896 commit 4713998
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-eels-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@talend/design-system": patch
---

Fix issue with Select component being recreated instead of updated
29 changes: 13 additions & 16 deletions packages/design-system/src/components/Form/Field/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { forwardRef, Children } from 'react';
import { Children, forwardRef } from 'react';
import type { Ref } from 'react';
import { isElement } from 'react-is';
import Input from '../Input';

import { useId } from '../../../../useId';
import {
FieldPrimitive,
FieldPropsPrimitive,
SelectPrimitive,
SelectPrimitiveProps,
} from '../../Primitives';
import { useId } from '../../../../useId';
import Input from '../Input';

export type SelectProps = FieldPropsPrimitive &
Omit<SelectPrimitiveProps, 'className' | 'style' | 'isAffix'> & { readOnly?: boolean };

const SelectField = forwardRef((fieldProps: SelectProps, ref: Ref<HTMLSelectElement>) => {
return <SelectPrimitive {...fieldProps} ref={ref} />;
});

SelectField.displayName = 'SelectField';

const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTMLInputElement>) => {
const {
label,
Expand Down Expand Up @@ -69,18 +76,6 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
);
}

function SelectField(fieldProps: Omit<SelectProps, 'children'>) {
return (
<SelectPrimitive
hasError={hasError || false}
{...fieldProps}
ref={ref as Ref<HTMLSelectElement>}
>
{children}
</SelectPrimitive>
);
}

return (
<FieldPrimitive
label={label}
Expand All @@ -101,7 +96,9 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
label={label}
id={fieldID}
{...rest}
/>
>
{children}
</SelectField>
</FieldPrimitive>
);
});
Expand Down

0 comments on commit 4713998

Please sign in to comment.