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

[TextField] Fix TypeScript FormHelperTextProps component prop #31931

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 3 additions & 1 deletion packages/mui-material/src/TextField/TextField.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export interface BaseTextFieldProps
/**
* Props applied to the [`FormHelperText`](/api/form-helper-text/) element.
*/
FormHelperTextProps?: Partial<FormHelperTextProps>;
FormHelperTextProps?: Partial<
FormHelperTextProps<React.ElementType, { component?: React.ElementType }>
>;
/**
* If `true`, the input will take up the full width of its container.
* @default false
Expand Down
17 changes: 17 additions & 0 deletions packages/mui-material/src/TextField/TextField.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,20 @@ function FocusHandlerTest() {

return null;
}

function FormHelperTextPropsTest() {
const validTagName = <TextField FormHelperTextProps={{ component: 'div' }} />;

const validReactComponent = (
<TextField FormHelperTextProps={{ component: ({ children }) => <div>${children}</div> }} />
);

// @ts-expect-error
const invalidTagName = <TextField FormHelperTextProps={{ component: 'invalid' }} />;

// @ts-expect-error
const invalidJSXTag = <TextField FormHelperTextProps={{ component: <div /> }} />;

// @ts-expect-error
const invalidNumericParam = <TextField FormHelperTextProps={{ component: 12345 }} />;
}
12 changes: 12 additions & 0 deletions packages/mui-material/src/TextField/TextField.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ describe('<TextField />', () => {
expect(getDescriptionOf(getByRole('textbox'))).to.have.class('foo');
});

it('should honor FormHelperTextProps component', () => {
const { getByTestId } = render(
<TextField
helperText="Foo bar"
FormHelperTextProps={{ component: 'div', 'data-testid': 'helper-text' }}
variant="standard"
/>,
);

expect(getByTestId('helper-text')).to.have.tagName('div');
});

it('has an accessible description', () => {
const { getByRole } = render(
<TextField
Expand Down