Skip to content

Commit 91630b2

Browse files
committed
Fix <ReferenceArrayInput> does not accept alwaysOn prop
1 parent b7c6162 commit 91630b2

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

packages/ra-core/src/controller/input/ReferenceArrayInputBase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { InputProps } from '../../form/types';
2+
import { InputProps } from '../../form/useInput';
33
import {
44
useReferenceArrayInputController,
55
type UseReferenceArrayInputParams,

packages/ra-core/src/form/types.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/ra-ui-materialui/src/input/ReferenceArrayInput.spec.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { DatagridInput } from './DatagridInput';
2222
import { TextField } from '../field';
2323
import { ReferenceArrayInput } from './ReferenceArrayInput';
2424
import { SelectArrayInput } from './SelectArrayInput';
25-
import { DifferentIdTypes } from './ReferenceArrayInput.stories';
25+
import { AsFilters, DifferentIdTypes } from './ReferenceArrayInput.stories';
2626

2727
describe('<ReferenceArrayInput />', () => {
2828
const defaultProps = {
@@ -292,4 +292,15 @@ describe('<ReferenceArrayInput />', () => {
292292
})
293293
).toBeNull();
294294
});
295+
296+
it('can be used as a list filter', async () => {
297+
render(<AsFilters />);
298+
await screen.findByText('band_2');
299+
fireEvent.click(screen.getByText('Members'));
300+
fireEvent.click(screen.getByText('artist_2'));
301+
await waitFor(() => {
302+
expect(screen.queryByText('band_2')).toBeNull();
303+
});
304+
await screen.findByText('band_1');
305+
});
295306
});

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { ReferenceArrayInput } from './ReferenceArrayInput';
2020
import { AutocompleteArrayInput } from './AutocompleteArrayInput';
2121
import { SelectArrayInput } from './SelectArrayInput';
2222
import { CheckboxGroupInput } from './CheckboxGroupInput';
23+
import { List, Datagrid } from '../list';
2324

2425
export default { title: 'ra-ui-materialui/input/ReferenceArrayInput' };
2526

@@ -77,6 +78,51 @@ export const Basic = () => (
7778
</TestMemoryRouter>
7879
);
7980

81+
export const AsFilters = () => {
82+
const fakeData = {
83+
bands: [
84+
{ id: 1, name: 'band_1', members: [2] },
85+
{ id: 2, name: 'band_2', members: [3] },
86+
],
87+
artists: [
88+
{ id: 1, name: 'artist_1' },
89+
{ id: 2, name: 'artist_2' },
90+
{ id: 3, name: 'artist_3' },
91+
],
92+
};
93+
return (
94+
<TestMemoryRouter initialEntries={['/bands']}>
95+
<AdminContext
96+
dataProvider={fakeRestProvider(fakeData, false)}
97+
i18nProvider={i18nProvider}
98+
>
99+
<AdminUI>
100+
<Resource name="tags" recordRepresentation={'name'} />
101+
<Resource
102+
name="bands"
103+
list={() => (
104+
<List
105+
filters={[
106+
<ReferenceArrayInput
107+
alwaysOn
108+
key="test"
109+
reference="artists"
110+
source="members"
111+
/>,
112+
]}
113+
>
114+
<Datagrid>
115+
<TextField source="name" />
116+
</Datagrid>
117+
</List>
118+
)}
119+
/>
120+
</AdminUI>
121+
</AdminContext>
122+
</TestMemoryRouter>
123+
);
124+
};
125+
80126
export const WithAutocompleteInput = () => (
81127
<AdminContext
82128
dataProvider={dataProvider}

0 commit comments

Comments
 (0)