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

Fixed number input label issue #6361

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
11 changes: 11 additions & 0 deletions packages/ra-core/src/util/FieldTitle.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,15 @@ describe('FieldTitle', () => {
const { container } = render(<FieldTitle label="foo" isRequired />);
expect(container.firstChild.textContent).toEqual('foo *');
});

it('should return null if label is false', () => {
const { container } = render(<FieldTitle label={false} isRequired />);
expect(container.firstChild).toBeNull();
});

it('should return null if label is empty string', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the desired behavior. An empty string should lead to an empty label (not the absence of label)

const { container } = render(<FieldTitle label="" isRequired />);
expect(container.firstChild).toBeNull();
});

});
8 changes: 7 additions & 1 deletion packages/ra-core/src/util/FieldTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface Props {
isRequired?: boolean;
resource?: string;
source?: string;
label?: string | ReactElement;
label?: string | ReactElement | false;
}

export const FieldTitle: FunctionComponent<Props> = ({
Expand All @@ -18,9 +18,15 @@ export const FieldTitle: FunctionComponent<Props> = ({
isRequired,
}) => {
const translate = useTranslate();

if (label === false || label === '') {
return null;
}

if (label && typeof label !== 'string') {
return label;
}

return (
<span>
{translate(
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-ui-materialui/src/input/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const NumberInput: FunctionComponent<NumberInputProps> = ({
};

NumberInput.propTypes = {
label: PropTypes.string,
label: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
options: PropTypes.object,
resource: PropTypes.string,
source: PropTypes.string,
Expand Down