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(field): making description show up #3675

Merged
merged 2 commits into from
Apr 7, 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/slow-rice-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@aws-amplify/ui-react": patch
---

fix(field): making description show up
11 changes: 6 additions & 5 deletions packages/react/src/primitives/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ const FieldPrimitive: Primitive<FieldPrimitiveProps, typeof Flex> = (
{...rest}
>
{label ? <Label visuallyHidden={labelHidden}>{label}</Label> : null}
{descriptiveText ? (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, why remove this logic? Shouldn't descriptiveText be provided to show the descriptive text?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but why did that cause a bug?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't cause the bug, the bug was I was passing it as a child instead of prop

<FieldDescription labelHidden={labelHidden}>
{descriptiveText}
</FieldDescription>
) : null}

<FieldDescription
labelHidden={labelHidden}
descriptiveText={descriptiveText}
/>

{children}
{errorMessage ? (
<FieldErrorMessage hasError={hasError} errorMessage={errorMessage} />
Expand Down
69 changes: 69 additions & 0 deletions packages/react/src/primitives/Field/__tests__/Field.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as React from 'react';
import { render } from '@testing-library/react';

import { Field } from '../Field';
import { ComponentClassNames } from '../../shared/constants';

describe('Field component', () => {
it('should match snapshot', () => {
const { container } = render(
<Field
label="label"
descriptiveText="some description"
errorMessage="error"
hasError
>
<div>hi</div>
</Field>
);
expect(container).toMatchSnapshot();
});

it('should render a label', () => {
const { getByText } = render(<Field label="label" />);
const descriptionElement = getByText('label');
expect(descriptionElement).toHaveClass(ComponentClassNames.Label);
});

it('should render descriptive text', () => {
const { getByText } = render(
<Field label="label" descriptiveText="description" />
);
const descriptionElement = getByText('description');
expect(descriptionElement).toHaveClass(
ComponentClassNames.FieldDescription
);
});

it('should render error message', () => {
const { getByText } = render(
<Field label="label" errorMessage="error" hasError />
);
const descriptionElement = getByText('error');
expect(descriptionElement).toHaveClass(
ComponentClassNames.FieldErrorMessage
);
});

it('should render if it has a "labelHidden" prop is `true`, as long as there\'s descriptiveText', () => {
const { getByText } = render(
<Field label="label" descriptiveText="some description" labelHidden />
);
const descriptionElement = getByText('some description');
expect(descriptionElement).toHaveClass(ComponentClassNames.VisuallyHidden);
});

it('should not be hidden if it has a "labelHidden" prop is `false`', () => {
const { getByText } = render(
<Field
label="label"
descriptiveText="some description"
labelHidden={false}
/>
);
const descriptionElement = getByText('some description');
expect(descriptionElement).not.toHaveClass(
ComponentClassNames.VisuallyHidden
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Field component should match snapshot 1`] = `
<div>
<div
class="amplify-flex amplify-field"
>
<label
class="amplify-label"
>
label
</label>
<p
class="amplify-text amplify-field__description"
data-testid="qa-field-description"
>
some description
</p>
<div>
hi
</div>
<p
class="amplify-text amplify-field__error-message"
>
error
</p>
</div>
</div>
`;