Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@ describe('<TextareaAutosize />', () => {

expect(asFragment()).toMatchSnapshot();
});

it('renders component with custom class name.', () => {
const props = {
className: 'custom-classname',
};
const { getByRole } = render(<TextareaAutosize {...props} />);

const textArea = getByRole('textbox');

expect(textArea).toHaveClass('custom-classname');
});
});
11 changes: 10 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface TextareaAutosizeProps extends Omit<TextareaProps, 'style'> {
onHeightChange?: (height: number, meta: TextareaHeightChangeMeta) => void;
cacheMeasurements?: boolean;
style?: Style;
className?: string;
}

const TextareaAutosize: React.ForwardRefRenderFunction<
Expand All @@ -32,6 +33,7 @@ const TextareaAutosize: React.ForwardRefRenderFunction<
cacheMeasurements,
maxRows,
minRows,
className,
onChange = noop,
onHeightChange = noop,
...props
Expand Down Expand Up @@ -95,7 +97,14 @@ const TextareaAutosize: React.ForwardRefRenderFunction<
useWindowResizeListener(resizeTextarea);
}

return <textarea {...props} onChange={handleChange} ref={ref} />;
return (
<textarea
{...props}
className={className}
onChange={handleChange}
ref={ref}
/>
);
};

export default /* #__PURE__ */ React.forwardRef(TextareaAutosize);