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

Fix Labeled ignores fullWidth when label is false #8689

Merged
merged 1 commit into from
Mar 2, 2023
Merged
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 packages/ra-ui-materialui/src/Labeled.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import { RecordContextProvider, ResourceContext } from 'ra-core';
import { TextField } from './field';
import { Labeled } from './Labeled';
import { Box, Stack } from '@mui/material';

export default { title: 'ra-ui-materialui/detail/Labeled' };

Expand Down Expand Up @@ -71,3 +72,31 @@ export const NoDoubleLabel = () => (
</RecordContextProvider>
</ResourceContext.Provider>
);

export const FullWidth = () => (
<Stack alignItems="flex-start">
<ResourceContext.Provider value="books">
<RecordContextProvider value={record}>
<Labeled label="title" fullWidth>
<Box border="1px solid">
<TextField source="title" />
</Box>
</Labeled>
</RecordContextProvider>
</ResourceContext.Provider>
</Stack>
);

export const FullWidthNoLabel = () => (
<Stack alignItems="flex-start">
<ResourceContext.Provider value="books">
<RecordContextProvider value={record}>
<Labeled label={false} fullWidth>
<Box border="1px solid">
<TextField source="title" />
</Box>
</Labeled>
</RecordContextProvider>
</ResourceContext.Provider>
</Stack>
);
41 changes: 20 additions & 21 deletions packages/ra-ui-materialui/src/Labeled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ export const Labeled = ({
resource,
source,
...rest
}: LabeledProps) =>
label !== false &&
children.props.label !== false &&
typeof children.type !== 'string' &&
// @ts-ignore
children.type?.displayName !== 'Labeled' &&
// @ts-ignore
children.type?.displayName !== 'Labeled' ? (
<Root
// @ts-ignore https://github.com/mui/material-ui/issues/29875
component={component}
className={clsx(className, {
[LabeledClasses.fullWidth]: fullWidth,
})}
{...rest}
>
}: LabeledProps) => (
<Root
// @ts-ignore https://github.com/mui/material-ui/issues/29875
component={component}
className={clsx(className, {
[LabeledClasses.fullWidth]: fullWidth,
})}
{...rest}
>
{label !== false &&
children.props.label !== false &&
typeof children.type !== 'string' &&
// @ts-ignore
children.type?.displayName !== 'Labeled' &&
// @ts-ignore
children.type?.displayName !== 'Labeled' ? (
<Typography color={color} className={LabeledClasses.label}>
<FieldTitle
label={label || children.props.label}
Expand All @@ -55,11 +55,10 @@ export const Labeled = ({
isRequired={isRequired}
/>
</Typography>
{children}
</Root>
) : (
<div className={className}>{children}</div>
);
) : null}
{children}
</Root>
);

Labeled.displayName = 'Labeled';

Expand Down