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(TDOPS-5409/forms): Link render below Password/Text field #4962

Merged
merged 3 commits into from
Oct 27, 2023
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
5 changes: 5 additions & 0 deletions .changeset/twelve-games-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@talend/react-forms': patch
---

TDOPS-5409 - fix Link render below Password/Text field
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,14 @@ export const Password = () => (
readOnly
defaultValue="TalendPassword2012"
/>
<Form.Password
name="password"
label="Password with link"
defaultValue="TalendPassword2012"
link={{
href: 'https://talend.com/reset/password',
children: 'Need help to log in?',
}}
/>
</StackVertical>
);
3 changes: 0 additions & 3 deletions packages/forms/src/UIForm/fields/Text/PasswordWidget/index.js

This file was deleted.

9 changes: 4 additions & 5 deletions packages/forms/src/UIForm/fields/Text/Text.component.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/* eslint-disable jsx-a11y/no-autofocus */
import PropTypes from 'prop-types';
import { get, omit } from 'lodash';
import { Link } from '@talend/design-system';
import get from 'lodash/get';
import { Form } from '@talend/design-system';
import FieldTemplate from '../FieldTemplate';
import { generateDescriptionId, generateErrorId } from '../../Message/generateId';
import PasswordWidget from './PasswordWidget';

import { convertValue, extractDataAttributes } from '../../utils/properties';

Expand Down Expand Up @@ -63,12 +62,12 @@ export default function Text(props) {
valueIsUpdating={valueIsUpdating}
>
{type === 'password' ? (
<PasswordWidget
<Form.Password
{...fieldProps}
aria-invalid={!isValid}
aria-required={get(schema, 'required')}
aria-describedby={`${descriptionId} ${errorId}`}
link={link && <Link {...omit(link, ['label'])}> {link.label} </Link>}
link={link}
/>
) : (
<input
Expand Down
31 changes: 30 additions & 1 deletion packages/forms/src/UIForm/fields/Text/Text.component.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('Text field', () => {
expect(screen.getByLabelText('My input title')).toHaveAttribute('autoComplete', 'off');
});

it('should pass labelProps to FieldTemplate', () => {
it('should pass labelProps to Text field', () => {
// given
const labelProps = { className: 'hello' };
const props = {
Expand All @@ -249,4 +249,33 @@ describe('Text field', () => {
// then
expect(screen.getByText('My input title')).toHaveClass('hello');
});

it('should pass link props and password type to Text field', () => {
// given
const link = {
href: 'https://talend.com',
title: 'Helps to reset your password',
children: 'Need help to log in?',
'aria-label': 'Need help to log in?',
};

const props = {
...defaultProps,
schema: {
autoFocus: true,
placeholder: 'Enter your password',
required: true,
title: 'Password',
type: 'password',
link,
},
};

// when
render(<Text {...props} />);

// then
expect(screen.getByTitle(link.title)).toHaveTextContent(link.children);
expect(screen.getByTestId('link.icon.external')).toBeVisible();
});
});
5 changes: 3 additions & 2 deletions packages/forms/stories/json/fields/core-text.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
"type": "password",
"link": {
"href": "https://talend.com",
"label": "Forget?",
"aria-label": "Need help to log in?"
"title": "Forget?",
"aria-label": "Need help to log in?",
"children": "Need help to log in?"
}
}
],
Expand Down
Loading