File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
packages/@headlessui-react Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212- Expose ` disabled ` state on ` <Tab /> ` component ([ #2918 ] ( https://github.com/tailwindlabs/headlessui/pull/2918 ) )
1313- Prevent default behaviour when clicking outside of a ` Dialog.Panel ` ([ #2919 ] ( https://github.com/tailwindlabs/headlessui/pull/2919 ) )
1414- Use ` isFocused ` instead of ` isFocusVisible ` for ` Input ` and ` Textarea ` components ([ #2940 ] ( https://github.com/tailwindlabs/headlessui/pull/2940 ) )
15+ - Ensure ` children ` prop of ` Field ` component can be a render prop ([ #2941 ] ( https://github.com/tailwindlabs/headlessui/pull/2941 ) )
1516
1617## [ 2.0.0-alpha.4] - 2024-01-03
1718
Original file line number Diff line number Diff line change @@ -14,6 +14,25 @@ describe('Rendering', () => {
1414 expect ( container . firstChild ) . not . toHaveAttribute ( 'aria-disabled' , 'true' )
1515 } )
1616
17+ it ( 'should render a `Field` component with a render prop' , async ( ) => {
18+ let { container } = render (
19+ < Field >
20+ { ( slot ) => {
21+ return (
22+ < div data-slot = { JSON . stringify ( slot ) } >
23+ < input />
24+ </ div >
25+ )
26+ } }
27+ </ Field >
28+ )
29+
30+ expect ( container . querySelector ( '[data-slot]' ) ?. getAttribute ( 'data-slot' ) ) . toEqual (
31+ JSON . stringify ( { disabled : false } )
32+ )
33+ expect ( container . firstChild ) . not . toHaveAttribute ( 'aria-disabled' , 'true' )
34+ } )
35+
1736 it ( 'should add `aria-disabled` when a `Field` is disabled' , async ( ) => {
1837 let { container } = render (
1938 < Field disabled >
Original file line number Diff line number Diff line change @@ -53,7 +53,13 @@ function FieldFn<TTag extends ElementType = typeof DEFAULT_FIELD_TAG>(
5353 ourProps,
5454 theirProps : {
5555 ...theirProps ,
56- children : < FormFieldsProvider > { theirProps . children } </ FormFieldsProvider > ,
56+ children : (
57+ < FormFieldsProvider >
58+ { typeof theirProps . children === 'function'
59+ ? theirProps . children ( slot )
60+ : theirProps . children }
61+ </ FormFieldsProvider >
62+ ) ,
5763 } ,
5864 slot,
5965 defaultTag : DEFAULT_FIELD_TAG ,
You can’t perform that action at this time.
0 commit comments