Skip to content

Commit 046ea28

Browse files
authored
Merge pull request #10571 from marmelab/fix-helpertext-empty-string-handling
Fix helperText has wrong height when passing an empty string
2 parents 87d653e + 91f4f90 commit 046ea28

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

packages/ra-ui-materialui/src/input/InputHelperText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const InputHelperText = (props: InputHelperTextProps) => {
1818
return helperText;
1919
}
2020

21-
if (typeof helperText === 'string') {
21+
if (typeof helperText === 'string' && helperText.length > 0) {
2222
return <>{translate(helperText, { _: helperText })}</>;
2323
}
2424

packages/ra-ui-materialui/src/input/TextInput.stories.tsx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,33 @@ export const DefaultValue = () => (
8989
</Wrapper>
9090
);
9191

92-
export const HelperText = () => (
92+
export const HelperText = ({
93+
helperText = 'Number of times the post was read',
94+
}: {
95+
helperText: any;
96+
}) => (
9397
<Wrapper>
9498
<TextInput source="title" />
9599
<TextInput source="title" helperText={false} />
96-
<TextInput
97-
source="title"
98-
helperText="Number of times the post was read"
99-
/>
100+
<TextInput source="title" helperText={helperText} />
100101
</Wrapper>
101102
);
102103

104+
HelperText.argTypes = {
105+
helperText: {
106+
options: ['text', 'false', 'empty string'],
107+
mapping: {
108+
text: 'Number of times the post was read',
109+
false: false,
110+
'empty string': '',
111+
},
112+
control: { type: 'select' },
113+
},
114+
};
115+
HelperText.args = {
116+
helperText: 'text',
117+
};
118+
103119
export const Label = () => (
104120
<Wrapper>
105121
<TextInput source="title" />

0 commit comments

Comments
 (0)