@@ -15,7 +15,11 @@ import {
1515 ReferenceArrayInputBase ,
1616 ReferenceArrayInputBaseProps ,
1717} from './ReferenceArrayInputBase' ;
18- import { ChoicesProps , useChoicesContext } from '../../form' ;
18+ import {
19+ ChoicesContextValue ,
20+ ChoicesProps ,
21+ useChoicesContext ,
22+ } from '../../form' ;
1923import { useGetRecordRepresentation } from '../..' ;
2024
2125export default { title : 'ra-core/controller/ReferenceArrayInputBase' } ;
@@ -51,8 +55,15 @@ const i18nProvider = polyglotI18nProvider(() => englishMessages);
5155const CheckboxGroupInput = (
5256 props : Omit < InputProps , 'source' > & ChoicesProps
5357) => {
54- const { allChoices, isPending, error, resource, source, total } =
55- useChoicesContext ( props ) ;
58+ const choicesContext = useChoicesContext ( props ) ;
59+
60+ return < CheckboxGroupInputBase { ...props } { ...choicesContext } /> ;
61+ } ;
62+
63+ const CheckboxGroupInputBase = (
64+ props : Omit < InputProps , 'source' > & ChoicesProps & ChoicesContextValue
65+ ) => {
66+ const { allChoices, isPending, error, resource, source, total } = props ;
5667 const input = useInput ( { ...props , source } ) ;
5768 const getRecordRepresentation = useGetRecordRepresentation ( resource ) ;
5869
@@ -141,6 +152,53 @@ Basic.argTypes = {
141152 meta : { control : 'boolean' } ,
142153} ;
143154
155+ export const WithRender = ( {
156+ dataProvider = defaultDataProvider ,
157+ meta,
158+ ...props
159+ } : Partial < ReferenceArrayInputBaseProps > & {
160+ dataProvider ?: DataProvider ;
161+ meta ?: boolean ;
162+ } ) => (
163+ < TestMemoryRouter initialEntries = { [ '/posts/create' ] } >
164+ < CoreAdmin dataProvider = { dataProvider } i18nProvider = { i18nProvider } >
165+ < Resource
166+ name = "posts"
167+ create = {
168+ < CreateBase resource = "posts" record = { { tags_ids : [ 1 , 3 ] } } >
169+ < h1 > Create Post</ h1 >
170+ < Form >
171+ < ReferenceArrayInputBase
172+ reference = "tags"
173+ resource = "posts"
174+ source = "tags_ids"
175+ queryOptions = {
176+ meta ? { meta : { foo : 'bar' } } : { }
177+ }
178+ { ...props }
179+ render = { context => (
180+ < CheckboxGroupInputBase
181+ { ...context }
182+ source = "tags_ids"
183+ />
184+ ) }
185+ />
186+ </ Form >
187+ </ CreateBase >
188+ }
189+ />
190+ </ CoreAdmin >
191+ </ TestMemoryRouter >
192+ ) ;
193+
194+ WithRender . args = {
195+ meta : false ,
196+ } ;
197+
198+ WithRender . argTypes = {
199+ meta : { control : 'boolean' } ,
200+ } ;
201+
144202export const WithError = ( ) => (
145203 < TestMemoryRouter initialEntries = { [ '/posts/create' ] } >
146204 < CoreAdmin
0 commit comments