Skip to content

Commit ad22c42

Browse files
authored
Merge pull request #9174 from marmelab/fix-singlefieldlist-link-color
Fix SingleFieldList children don't use default link color
2 parents e9b7582 + 9e11df6 commit ad22c42

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

docs/ArrayField.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const PostShow = () => (
5353
<SimpleShowLayout>
5454
<TextField source="title" />
5555
<ArrayField source="tags">
56-
<SingleFieldList>
56+
<SingleFieldList linkType={false}>
5757
<ChipField source="name" size="small" />
5858
</SingleFieldList>
5959
</ArrayField>
@@ -89,7 +89,7 @@ const PostShow = () => (
8989
```jsx
9090
{/* using SingleFieldList as child */}
9191
<ArrayField source="tags">
92-
<SingleFieldList>
92+
<SingleFieldList linkType={false}>
9393
<ChipField source="name" />
9494
</SingleFieldList>
9595
</ArrayField>
@@ -210,7 +210,7 @@ By default, `<ArrayField>` displays the items in the order they are stored in th
210210
{% raw %}
211211
```jsx
212212
<ArrayField source="tags" sort={{ field: 'name', order: 'ASC' }}>
213-
<SingleFieldList>
213+
<SingleFieldList linkType={false}>
214214
<ChipField source="name" />
215215
</SingleFieldList>
216216
</ArrayField>
@@ -244,7 +244,7 @@ const PostShow = () => (
244244
<SimpleShowLayout>
245245
<TextField source="title" />
246246
<ArrayField source="tags">
247-
<SingleFieldList>
247+
<SingleFieldList linkType={false}>
248248
<SelectedChip />
249249
</SingleFieldList>
250250
</ArrayField>

docs/SingleFieldList.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ const PostList = () => (
5656

5757
![SingleFieldList in Datagrid](./img/singlefieldlist-datagrid.png)
5858

59+
## Props
60+
5961
`<SingleFieldList>` accepts the following props:
6062

61-
* [`linkType`](#linktype)
62-
* [`sx`](#sx-css-api)
63+
| Prop | Required | Type | Default | Description |
64+
| ----------- | -------- | ------------------------- | ------- | --------------------------------------------- |
65+
| `linkType` | Optional | `'edit' | 'show' | false` | `edit` | The target of the link on each item |
66+
| `sx` | Optional | `object` | | The sx props of the Material UI Box component |
6367

6468
## `linkType`
6569

@@ -78,14 +82,12 @@ The `<SingleFieldList>` items link to the edition page by default. You can set t
7882
</ReferenceArrayField>
7983
```
8084

81-
8285
`linkType` accepts the following values:
8386

8487
* `linkType="edit"`: links to the edit page. This is the default behavior.
8588
* `linkType="show"`: links to the show page.
8689
* `linkType={false}`: does not create any link.
8790

88-
8991
## `sx`: CSS API
9092

9193
The `<SingleFieldList>` component accepts the usual `className` prop. You can also override the styles of the inner components thanks to the `sx` property. This property accepts the following subclasses:

packages/ra-ui-materialui/src/field/ArrayField.stories.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let books = [
3030
export const Basic = () => (
3131
<MemoryRouter>
3232
<ArrayField record={{ id: 123, books }} source="books">
33-
<SingleFieldList>
33+
<SingleFieldList linkType={false}>
3434
<ChipField source="title" />
3535
</SingleFieldList>
3636
</ArrayField>
@@ -48,7 +48,7 @@ export const PerPage = () => (
4848
source="books"
4949
perPage={2}
5050
>
51-
<SingleFieldList>
51+
<SingleFieldList linkType={false}>
5252
<ChipField source="title" />
5353
</SingleFieldList>
5454
<Pagination />
@@ -65,7 +65,7 @@ export const Sort = () => (
6565
source="books"
6666
sort={{ field: 'title', order: 'ASC' }}
6767
>
68-
<SingleFieldList>
68+
<SingleFieldList linkType={false}>
6969
<ChipField source="title" />
7070
</SingleFieldList>
7171
</ArrayField>
@@ -79,7 +79,7 @@ export const Filter = () => (
7979
source="books"
8080
filter={{ title: 'Anna Karenina' }}
8181
>
82-
<SingleFieldList>
82+
<SingleFieldList linkType={false}>
8383
<ChipField source="title" />
8484
</SingleFieldList>
8585
</ArrayField>
@@ -122,7 +122,7 @@ const SelectedChip = () => {
122122
export const ListContext = () => (
123123
<MemoryRouter>
124124
<ArrayField record={{ id: 123, books }} source="books">
125-
<SingleFieldList sx={{ p: 2 }}>
125+
<SingleFieldList sx={{ p: 2 }} linkType={false}>
126126
<SelectedChip />
127127
</SingleFieldList>
128128
<SortButton /> <FilterButton />
@@ -155,7 +155,7 @@ export const InShowLayout = () => (
155155
<SimpleShowLayout>
156156
<TextField source="title" />
157157
<ArrayField source="tags">
158-
<SingleFieldList>
158+
<SingleFieldList linkType={false}>
159159
<ChipField source="name" size="small" />
160160
</SingleFieldList>
161161
</ArrayField>

packages/ra-ui-materialui/src/field/ReferenceManyField.stories.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { createTheme } from '@mui/material/styles';
1111
import { TextField } from '../field';
1212
import { ReferenceManyField } from './ReferenceManyField';
1313
import { Datagrid } from '../list/datagrid/Datagrid';
14+
import { SingleFieldList } from '../list';
1415
import { Notification } from '../layout/Notification';
1516
import { FilterForm } from '../list';
1617
import { TextInput } from '../input';
@@ -78,6 +79,16 @@ export const Basic = () => (
7879
</Wrapper>
7980
);
8081

82+
export const WithSingleFieldList = () => (
83+
<Wrapper>
84+
<ReferenceManyField reference="books" target="author_id">
85+
<SingleFieldList sx={{ gap: 1 }}>
86+
<TextField source="title" />
87+
</SingleFieldList>
88+
</ReferenceManyField>
89+
</Wrapper>
90+
);
91+
8192
export const WithFilter = () => (
8293
<Wrapper>
8394
<ReferenceManyField reference="books" target="author_id">

packages/ra-ui-materialui/src/list/SingleFieldList.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import { Link } from '../Link';
3535
* Set the linkType prop to "show" to link to the <Show> page instead.
3636
*
3737
* @example
38-
* <ReferenceManyField reference="books" target="author_id" linkType="show">
39-
* <SingleFieldList>
38+
* <ReferenceManyField reference="books" target="author_id">
39+
* <SingleFieldList linkType="show">
4040
* <ChipField source="title" />
4141
* </SingleFieldList>
4242
* </ReferenceManyField>
@@ -45,8 +45,8 @@ import { Link } from '../Link';
4545
* `linkType` to false.
4646
*
4747
* @example
48-
* <ReferenceManyField reference="books" target="author_id" linkType={false}>
49-
* <SingleFieldList>
48+
* <ReferenceManyField reference="books" target="author_id">
49+
* <SingleFieldList linkType={false}>
5050
* <ChipField source="title" />
5151
* </SingleFieldList>
5252
* </ReferenceManyField>
@@ -159,14 +159,17 @@ export const SingleFieldListClasses = {
159159
const Root = styled('div', {
160160
name: PREFIX,
161161
overridesResolver: (props, styles) => styles.root,
162-
})({
162+
})(({ theme }) => ({
163163
display: 'flex',
164164
flexWrap: 'wrap',
165165

166166
[`& .${SingleFieldListClasses.link}`]: {
167167
textDecoration: 'none',
168+
'& > *': {
169+
color: theme.palette.primary.main,
170+
},
168171
},
169-
});
172+
}));
170173

171174
// useful to prevent click bubbling in a datagrid with rowClick
172175
const stopPropagation = e => e.stopPropagation();

0 commit comments

Comments
 (0)