Skip to content

Commit

Permalink
fix: form control class missing for text area
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtute90 authored Nov 11, 2024
1 parent 1f16672 commit be15805
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/Input/TextArea.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { Ref, ReactNode, TextareaHTMLAttributes } from 'react';
import React, { ReactNode, Ref, TextareaHTMLAttributes } from 'react';

import { InputContainer } from './InputContainer';
import { getClasses, getValidationTextControlClass, useFocus } from './utils';
import type { CSSModule } from 'reactstrap/types/lib/utils';
import { InputContainer } from './InputContainer';
import { getClasses, getFormControlClass, getValidationTextControlClass, useFocus } from './utils';

export interface TextAreaProps extends TextareaHTMLAttributes<HTMLTextAreaElement> {
/** Etichetta del campo TextArea. */
Expand Down Expand Up @@ -56,6 +56,11 @@ export const TextArea = ({

const extraAttributes: { ['aria-describedby']?: string } = {};

//Chiamo questa funzione per impostare classNames a 'form-control'
const formControlClass = getFormControlClass(
{},
cssModule
);
// associate the input field with the help text
const infoId = id ? `${id}Description` : undefined;
if (id) {
Expand All @@ -73,6 +78,7 @@ export const TextArea = ({
label,
validationText,
normalized: Boolean(normalized),
formControlClass,
validationTextControlClass,
isFocused,
originalWrapperClass
Expand Down
12 changes: 10 additions & 2 deletions test/Input.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { act, fireEvent, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { act, fireEvent, render, screen } from '@testing-library/react';
import React from 'react';

import { Button, Icon, Input, preloadIcons } from '../src';

Expand Down Expand Up @@ -142,3 +142,11 @@ test('should have an left icon and right button', () => {
if (svg) expect(svg.nodeName).toBe('svg');
}
});

it('should have form-control as class', () => {
const { container } = render(
<Input />
);

expect(container.firstChild).toHaveClass('form-control');
});
12 changes: 10 additions & 2 deletions test/TextArea.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import React from 'react';

import { TextArea } from '../src';

Expand Down Expand Up @@ -34,3 +34,11 @@ test('should have a testId for resilient UI changes', () => {

expect(screen.getByTestId('test-id-text-area')).toBeTruthy();
});

it('should have form-control as class', () => {
const { container } = render(
<TextArea />
);

expect(container.firstChild).toHaveClass('form-control');
});
4 changes: 2 additions & 2 deletions test/__snapshots__/Storybook.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20588,7 +20588,7 @@ exports[`Stories Snapshots Documentazione/Form/Input AreaDiTesto 1`] = `
Esempio di area di testo
</label>
<textarea
class=""
class="form-control"
rows="3"
/>
<div
Expand All @@ -20611,7 +20611,7 @@ exports[`Stories Snapshots Documentazione/Form/Input AreaDiTestoConSegnaposto 1`
</label>
<textarea
aria-describedby="example-textarea-placeholderDescription"
class=""
class="form-control"
id="example-textarea-placeholder"
placeholder="Testo di esempio"
rows="3"
Expand Down

0 comments on commit be15805

Please sign in to comment.