Skip to content

Commit

Permalink
deps: bump react-hook-form to 7.X (#4947)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainseb authored Nov 6, 2023
1 parent 2500179 commit 8ec5602
Show file tree
Hide file tree
Showing 27 changed files with 195 additions and 126 deletions.
10 changes: 10 additions & 0 deletions .changeset/lovely-chefs-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@talend/design-docs': major
'@talend/react-stepper': major
'@talend/react-forms': major
---

deps: bump react-hook-form to 7.X

So if you are using rhf in your project you should also bump it and apply the migration guide
https://legacy.react-hook-form.com/migrate-v6-to-v7/
2 changes: 1 addition & 1 deletion packages/design-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"classnames": "^2.3.2",
"color-contrast-checker": "^2.1.0",
"figma-js": "^1.16.0",
"react-hook-form": "^7.47.0",
"pkg-dir": "^7.0.0",
"react-hook-form": "^6.15.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"use-overflow": "^1.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const AffixSelect = forwardRef((props: AffixSelectPropsType, ref: Ref<HTMLSelect
);
}
return (
<FieldPrimitive label={label} name={name} id={fieldID} hideLabel>
<FieldPrimitive label={label} name={name} id={fieldID} fieldId={fieldID} hideLabel>
<AffixSelectComponent {...rest} />
</FieldPrimitive>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const Datalist = forwardRef(
<>
<FieldPrimitive
id={datalistId}
fieldId={datalistId}
label={label}
hasError={hasError || false}
link={link}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
InputPrimitive,
InputPrimitiveProps,
} from '../../Primitives';
import { useId } from '../../../../useId';

type InputCopyProps = Omit<FieldPropsPrimitive, 'hasError'> &
Omit<InputPrimitiveProps, 'style' | 'className' | 'suffix'>;
Expand All @@ -30,6 +31,7 @@ const InputCopy = forwardRef(
}: InputCopyProps,
ref: Ref<HTMLInputElement | null>,
) => {
const inputId = useId(id, 'input-copy-');
const [copiedValue, setCopiedValue] = useState('');
const [copyError, setCopyError] = useState<Error | undefined | null>(null);
const [{ value: clipboardValue, error: clipboardError }, copyToClipboard] =
Expand Down Expand Up @@ -75,10 +77,12 @@ const InputCopy = forwardRef(
hasError={!!copyError}
hideLabel={hideLabel}
required={required}
fieldId={inputId}
name={name}
>
<InputPrimitive
{...rest}
id={inputId}
ref={inputRef}
value={value}
defaultValue={defaultValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,20 @@ const FieldFile = forwardRef(
ref: Ref<HTMLInputElement>,
) => {
const { label, hasError, link, description, id, name, hideLabel, required, ...rest } = props;
const fieldID = useId(id, 'field-');
return (
<FieldPrimitive
label={label}
hasError={hasError || false}
link={link}
description={description}
id={id}
fieldId={fieldID}
name={name}
hideLabel={hideLabel}
required={required}
>
<InputFile {...rest} ref={ref} />
<InputFile {...rest} id={fieldID} ref={ref} />
</FieldPrimitive>
);
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef } from 'react';
import type { Ref } from 'react';
import type { ChangeEvent, Ref } from 'react';

import classnames from 'classnames';

Expand All @@ -10,7 +10,7 @@ import { useControl } from '../../../../useControl';
import styles from './Input.ToggleSwitch.module.scss';

export type ToggleSwitchPropTypes = Omit<CheckboxPrimitiveType, 'onChange'> & {
onChange?: (checked: boolean) => void;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
};

export const ToggleSwitch = forwardRef(
Expand All @@ -33,7 +33,6 @@ export const ToggleSwitch = forwardRef(
onChangeKey: 'onChange',
valueKey: 'checked',
defaultValueKey: 'defaultChecked',
selector: e => e.target.checked,
defaultValue: false,
});

Expand Down
17 changes: 15 additions & 2 deletions packages/design-system/src/components/Form/Field/Input/Input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
InputPrimitive,
InputPrimitiveProps,
} from '../../Primitives';
import { useId } from '../../../../useId';

export type InputFieldProps = FieldPropsPrimitive &
Omit<InputPrimitiveProps, 'className' | 'styles'>;
Expand All @@ -24,18 +25,30 @@ const Field = forwardRef((props: InputFieldProps, ref: Ref<HTMLInputElement>) =>
required,
...rest
} = props;

const fieldID = useId(id, 'field-');

return (
<FieldPrimitive
label={label}
hasError={hasError || false}
link={link}
description={description}
id={id}
name={name}
hideLabel={hideLabel}
fieldId={fieldID}
name={name}
required={required}
>
<InputPrimitive {...rest} type={type} ref={ref} />
<InputPrimitive
{...rest}
id={fieldID}
type={type}
ref={ref}
hasError={hasError || false}
name={name}
required={required}
/>
</FieldPrimitive>
);
});
Expand Down
18 changes: 15 additions & 3 deletions packages/design-system/src/components/Form/Field/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SelectPrimitive,
SelectPrimitiveProps,
} from '../../Primitives';
import { useId } from '../../../../useId';

export type SelectProps = FieldPropsPrimitive &
Omit<SelectPrimitiveProps, 'className' | 'style' | 'isAffix'> & { readOnly?: boolean };
Expand All @@ -28,6 +29,8 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
...rest
} = props;

const fieldID = useId(id, 'field-');

if (readOnly) {
const values = Children.toArray(children).reduce((acc: string[], current) => {
if (!isElement(current)) {
Expand Down Expand Up @@ -57,7 +60,7 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
hasError={hasError || false}
link={link}
description={description}
id={id}
id={fieldID}
name={name}
hideLabel={hideLabel}
required={required}
Expand All @@ -66,7 +69,7 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
);
}

function SelectField(fieldProps: Omit<SelectProps, 'hasError' | 'name' | 'children' | 'label'>) {
function SelectField(fieldProps: Omit<SelectProps, 'children'>) {
return (
<SelectPrimitive
hasError={hasError || false}
Expand All @@ -86,10 +89,19 @@ const Select = forwardRef((props: SelectProps, ref: Ref<HTMLSelectElement | HTML
description={description}
id={id}
name={name}
fieldId={fieldID}
hideLabel={hideLabel}
required={required}
>
<SelectField defaultValue={defaultValue} {...rest} />
<SelectField
defaultValue={defaultValue}
hasError={hasError || false}
name={name}
label={label}
required={required}
id={fieldID}
{...rest}
/>
</FieldPrimitive>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TextareaPrimitive,
TextareaPrimitiveProps,
} from '../../Primitives';
import { useId } from '../../../../useId';

export type InputTextareaProps = FieldPropsPrimitive &
Omit<TextareaPrimitiveProps, 'className' | 'styles'> & { children?: string };
Expand All @@ -23,18 +24,28 @@ const Textarea = forwardRef((props: InputTextareaProps, ref: Ref<HTMLTextAreaEle
children,
...rest
} = props;

const fieldID = useId(id, 'field-');

return (
<FieldPrimitive
label={label}
hasError={hasError || false}
link={link}
description={description}
id={id}
fieldId={fieldID}
name={name}
hideLabel={hideLabel}
required={required}
>
<TextareaPrimitive defaultValue={defaultValue || children} {...rest} ref={ref} />
<TextareaPrimitive
defaultValue={defaultValue || children}
{...rest}
required={required}
id={fieldID}
ref={ref}
/>
</FieldPrimitive>
);
});
Expand Down
1 change: 1 addition & 0 deletions packages/design-system/src/components/Form/Form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('Form', () => {
</Form>
</main>,
);

expect(container.firstChild).toMatchSnapshot();
const results = await axe(document.body);
expect(results).toHaveNoViolations();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { cloneElement, forwardRef, ReactElement, Ref } from 'react';
import { forwardRef, ReactElement, Ref } from 'react';

import Link, { LinkProps } from '../../../Link/Link';
import { StackVertical } from '../../../Stack';
import Label, { LabelPrimitiveProps } from '../Label/Label';
import { InlineMessageDestructive, InlineMessageInformation } from '../../../InlineMessage';
import { VisuallyHidden } from '../../../VisuallyHidden';
import { useId } from '../../../../useId';

export type FieldStatusProps =
| {
Expand All @@ -26,33 +25,32 @@ export type FieldPropsPrimitive = {
required?: boolean;
} & FieldStatusProps;

type FieldPropsPrimitiveWithChildren = FieldPropsPrimitive & { children: ReactElement };
type FieldPropsPrimitiveWithChildren = FieldPropsPrimitive & {
children: ReactElement;
fieldId: string;
};

const Field = forwardRef(
(props: FieldPropsPrimitiveWithChildren, ref: Ref<HTMLInputElement | HTMLTextAreaElement>) => {
const {
children,
link,
id,
label,
name,
hasError = false,
hideLabel = false,
required = false,
description,
...rest
fieldId,
} = props;

const fieldID = useId(id, 'field-');

const labelProps = typeof label === 'string' ? { children: label } : { ...label };

const LabelComponent = hideLabel ? (
<VisuallyHidden>
<Label {...labelProps} htmlFor={fieldID} required={required} />
<Label {...labelProps} htmlFor={fieldId} required={required} />
</VisuallyHidden>
) : (
<Label {...labelProps} htmlFor={fieldID} required={required} />
<Label {...labelProps} htmlFor={fieldId} required={required} />
);

const Description = () => {
Expand All @@ -69,7 +67,7 @@ const Field = forwardRef(
return (
<StackVertical gap="XXS" align="stretch" justify="start" height="100%" noShrink>
{LabelComponent}
{cloneElement(children, { id: fieldID, hasError, name, required, ref, ...rest })}
{children}
{link && <Link {...link} />}
{description && <Description />}
</StackVertical>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ exports[`Form should render a11y html 1`] = `
<input
class="theme-inputFile__input theme-input"
id="field--mocked-uuid-3"
name="file"
type="file"
/>
<div
Expand Down Expand Up @@ -229,7 +228,6 @@ exports[`Form should render a11y html 1`] = `
<textarea
class="theme-textarea"
id="field--mocked-uuid-8"
name="textarea"
/>
</div>
<div
Expand All @@ -250,6 +248,7 @@ exports[`Form should render a11y html 1`] = `
<select
class="theme-select"
id="field--mocked-uuid-9"
label="Select"
name="select"
>
<option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { ButtonIcon } from '../../ButtonIcon';
import { Form } from '../../Form';
import { StackHorizontal } from '../../Stack';
import { I18N_DOMAIN_DESIGN_SYSTEM } from '../../constants';
import { useId } from '../../../useId';

import styles from './InlineEditingPrimitive.module.scss';

Expand Down Expand Up @@ -103,6 +104,7 @@ const InlineEditingPrimitive = forwardRef(

const [isEditing, setEditing] = useState<boolean>(false);
const [internalValue, setInternalValue] = useState<string | undefined>(defaultValue);
const inlineEditingId = useId(rest.id, 'inline-edit-');

// Displayed content depends on current mode
// Controlled mode - display value prop
Expand Down Expand Up @@ -177,6 +179,7 @@ const InlineEditingPrimitive = forwardRef(
description,
label,
name: label.replace(/\s/g, ''),
fieldId: inlineEditingId,
required,
maxLength,
placeholder,
Expand Down
Loading

0 comments on commit 8ec5602

Please sign in to comment.