Skip to content

Commit

Permalink
fix(TDOPS-5409/forms): Link render below Password/Text field (#4962)
Browse files Browse the repository at this point in the history
* fix(TDOPS-5409/forms): link under password field

* chore: update changeset

* fix: remove debug from test
  • Loading branch information
inna-i authored Oct 27, 2023
1 parent 3f9c8a7 commit 77826b0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 11 deletions.
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

0 comments on commit 77826b0

Please sign in to comment.