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

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

Merged
merged 29 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
07be73b
deps: bump react-hook-form to 7.X
romainseb Oct 20, 2023
d18e3ac
add changeset
romainseb Oct 20, 2023
a03bb9a
migrate component :)
romainseb Oct 23, 2023
4d64007
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Oct 23, 2023
71d4be5
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Oct 24, 2023
1174928
Merge 71d4be55bff3902d6a4cc3528cc3692a82ce467c into 59cf99b8f45e996df…
romainseb Oct 24, 2023
9e85cca
chore: yarn-deduplicate
github-actions[bot] Oct 24, 2023
0caddb5
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Oct 24, 2023
b1c52e2
update package.json
romainseb Oct 24, 2023
025fba9
fix rhf provider (for now)
romainseb Oct 25, 2023
e2ad731
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Oct 25, 2023
3aad454
update code
romainseb Oct 25, 2023
936349a
Handle default value
romainseb Oct 25, 2023
7c3dd40
update changeset
romainseb Oct 25, 2023
4772956
Update .changeset/lovely-chefs-remain.md
romainseb Oct 25, 2023
173db74
use RHF7 in design system form
romainseb Oct 25, 2023
3430bed
accessibility is broken :/
romainseb Oct 25, 2023
fe865b1
update
romainseb Oct 31, 2023
4c27c37
chore: update for accessibility
romainseb Oct 31, 2023
e29e1e7
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Oct 31, 2023
3369491
fix conflict issue
romainseb Oct 31, 2023
3e6651e
updatre
romainseb Oct 31, 2023
afa9165
fix e2e tests
romainseb Oct 31, 2023
2cd75a6
paris timezone ...
romainseb Oct 31, 2023
9715383
update typings
romainseb Oct 31, 2023
0119e3a
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Nov 2, 2023
9d80f41
update typings
romainseb Nov 2, 2023
38f8c18
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Nov 3, 2023
9fa7789
Merge branch 'master' into sromain/deps/bump-rhf
romainseb Nov 6, 2023
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
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
romainseb marked this conversation as resolved.
Show resolved Hide resolved

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
Loading