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
29 changes: 29 additions & 0 deletions src/base/FormHelperText/FormHelperText.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import FormHelperText from './FormHelperText';

describe('FormHelperText Component', () => {
it('renders children correctly', () => {
render(<FormHelperText>Sample Helper Text</FormHelperText>);
expect(screen.getByText('Sample Helper Text')).toBeInTheDocument();
});

it('forwards ref correctly to the underlying HTML element', () => {
const ref = React.createRef<HTMLParagraphElement>();
render(<FormHelperText ref={ref}>Ref Attached Text</FormHelperText>);
expect(ref.current).toBeInstanceOf(HTMLParagraphElement);
expect(ref.current?.textContent).toBe('Ref Attached Text');
});

it('applies custom className and props', () => {
render(
<FormHelperText data-testid="custom-helper" className="custom-class" error>
Error state text
</FormHelperText>
);
const element = screen.getByTestId('custom-helper');
expect(element).toHaveClass('custom-class');
expect(element).toHaveClass('Mui-error');
});
});
19 changes: 19 additions & 0 deletions src/base/FormHelperText/FormHelperText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import MuiFormHelperText, {
FormHelperTextProps as MuiFormHelperTextProps
} from '@mui/material/FormHelperText';
import React from 'react';

export type SistentFormHelperTextProps = MuiFormHelperTextProps;

export const FormHelperText = React.forwardRef<HTMLParagraphElement, SistentFormHelperTextProps>(
({ children, ...props }, ref) => {
return (
<MuiFormHelperText ref={ref} {...props}>
{children}
</MuiFormHelperText>
);
}
);
FormHelperText.displayName = 'FormHelperText';

export default FormHelperText;
1 change: 1 addition & 0 deletions src/base/FormHelperText/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './FormHelperText';
1 change: 1 addition & 0 deletions src/base/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ export * from './Toolbar';
export * from './Tooltip';
export * from './Typography';
export * from './Zoom';
export * from './FormHelperText';
Loading