Skip to content

Commit

Permalink
fix(FormLabel): remove span from Label for required input. (#286)
Browse files Browse the repository at this point in the history
Co-authored-by: Nathan Young <[email protected]>
  • Loading branch information
Jesse Carmine and nathanyoung authored Oct 20, 2020
1 parent a39545c commit a81f95d
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/components/FormLabel/FormLabel.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe('FormLabel', () => {

test('Label correctly renders with askterisk if field is required', () => {
render(<FormLabel inputId="myId" isFieldRequired>my label</FormLabel>);
const labelElement = screen.getByText('my label');
expect(labelElement).toHaveTextContent('*');
const labelElement = screen.getByText('my label *');
expect(labelElement).toBeInTheDocument();
});

test('Label correctly renders with error class if field has eror', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormLabel/FormLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const FormLabel: FC<FormLabelProps> = ({
return (
<label id={`${inputId}Label`} className={labelClasses} htmlFor={inputId}>
{children}
{isFieldRequired && <span>&nbsp;*</span>}
{isFieldRequired && <>&nbsp;*</>}
{helpText && (
<Box as="p" display="block" fontSize="sm" color="grey" className={styles['help-text']}>
{helpText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ describe('SelectInput', () => {
test('it renders an asterisk in the label', () => {
render(renderForm([], { isRequired: true }));

expect(screen.getByText(testLabelName)).toBeInTheDocument();
expect(screen.getByText('*')).toBeInTheDocument();
expect(screen.getByText(`${testLabelName} *`)).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ describe('FormikTextInput', () => {
test('Input correctly passes props to dependency label component', async () => {
const { getByText } = render(renderForm('', { isRequired: true }));
const submitButton = getByText('submit');
const labelElement = getByText(testLabelName);
const labelElement = getByText(`${testLabelName} *`);
expect(labelElement).toHaveAttribute('for', testLabelName);
expect(labelElement).toHaveTextContent('*');
expect(labelElement).toBeInTheDocument();

fireEvent.click(submitButton);
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ describe('FormikTextareaInput', () => {
test('Input correctly passes props to dependency label component', async () => {
const { getByText } = render(renderForm('', { isRequired: true }));
const submitButton = getByText('submit');
const labelElement = getByText(testLabelName);
const labelElement = getByText(`${testLabelName} *`);
expect(labelElement).toHaveAttribute('for', testLabelName);
expect(labelElement).toHaveTextContent('*');
expect(labelElement).toBeInTheDocument();

fireEvent.click(submitButton);
await waitFor(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/components/SelectInput/SelectInput.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ describe('SelectInput', () => {
/>,
);

expect(screen.getByText('Select Label')).toBeInTheDocument();
expect(screen.getByText('*')).toBeInTheDocument();
expect(screen.getByText('Select Label *')).toBeInTheDocument();
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/TextInput/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ describe('TextInput', () => {
test('it\'s label renders an asterisk indicating that it\'s required', () => {
render(<TextInput {...baseProps} isRequired />);

const labelElement = screen.getByText(baseProps.label);
const labelElement = screen.getByText(`${baseProps.label} *`);

expect(labelElement).toHaveTextContent('*');
expect(labelElement).toBeInTheDocument();
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/TextareaInput/TextareaInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ describe('TextareaInput', () => {
test("it's label renders an asterisk indicating that it's required", () => {
render(<TextareaInput {...baseProps} isRequired />);

const labelElement = screen.getByText(baseProps.label);
const labelElement = screen.getByText(`${baseProps.label} *`);

expect(labelElement).toHaveTextContent('*');
expect(labelElement).toBeInTheDocument();
});
});

Expand Down

0 comments on commit a81f95d

Please sign in to comment.