Skip to content

Commit

Permalink
fix array table will show labels wrapped by form card
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Jun 15, 2019
2 parents c8cb1d3 + 68ed3a3 commit 60e0917
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
33 changes: 23 additions & 10 deletions docs/Examples/antd/Relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ ReactDOM.render(<App />, document.getElementById('root'))
#### Demo 示例

```jsx
import React from 'react'
import React,{useState,useEffect} from 'react'
import ReactDOM from 'react-dom'
import { filter, withLatestFrom, map, debounceTime } from 'rxjs/operators'
import {
Expand All @@ -381,7 +381,26 @@ import { Button } from 'antd'
import Printer from '@uform/printer'
import 'antd/dist/antd.css'

const App = () => (

const App = () => {
const [values,setValues] = useState({})
useEffect(()=>{
setTimeout(()=>{
setValues({
aa: [
{
bb: 'aaaaa',
dd: [{ ee: '', ff: '' }]
},
{
bb: 'ccccc',
dd: [{ ee: '', ff: '' }]
}
]
})
},1000)
},[])
return (
<Printer>
<SchemaForm
effects={($, { setFieldState, getFieldState }) => {
Expand Down Expand Up @@ -460,14 +479,7 @@ const App = () => (
})
}}
onSubmit={v => console.log(v)}
defaultValue={{
aa: [
{
bb: 'aaaaa',
dd: [{ ee: '', ff: '' }]
}
]
}}
initialValues={values}
>
<FormBlock title="Block1">
<Field type="array" name="aa">
Expand Down Expand Up @@ -522,5 +534,6 @@ const App = () => (
</SchemaForm>
</Printer>
)
}
ReactDOM.render(<App />, document.getElementById('root'))
```
2 changes: 1 addition & 1 deletion packages/antd/src/fields/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FormCardsField = styled(

renderEmpty(title) {
return (
<Card title={title} className='card-list'>
<Card style={this.getProps('style')} title={title} className='card-list'>
{super.renderEmpty()}
</Card>
)
Expand Down
13 changes: 11 additions & 2 deletions packages/antd/src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,16 @@ const isTableColItem = (path, getSchema) => {

registerFieldMiddleware(Field => {
return props => {
const { name, errors, editable, path, required, schema, getSchema } = props
const {
name,
errors,
editable,
path,
required,
schema,
schemaPath,
getSchema
} = props
if (path.length === 0) return React.createElement(Field, props) // 根节点是不需要包FormItem的
return React.createElement(
FormConsumer,
Expand All @@ -479,7 +488,7 @@ registerFieldMiddleware(Field => {
label: schema.title,
noMinHeight: schema.type === 'object' && !schema['x-component'],
isTableColItem: isTableColItem(
path.slice(0, path.length - 2),
schemaPath.slice(0, schemaPath.length - 2),
getSchema
),
type: schema['x-component'] || schema['type'],
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/fields/cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const FormCardsField = styled(

renderEmpty(title) {
return (
<Card title={title} className='card-list' contentHeight='auto'>
<Card style={this.getProps('style')} title={title} className='card-list' contentHeight='auto'>
{super.renderEmpty()}
</Card>
)
Expand Down
13 changes: 11 additions & 2 deletions packages/next/src/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,16 @@ const isTableColItem = (path, getSchema) => {

registerFieldMiddleware(Field => {
return props => {
const { name, editable, errors, path, schema, getSchema, required } = props
const {
name,
editable,
errors,
path,
schemaPath,
schema,
getSchema,
required
} = props
if (path.length === 0) return React.createElement(Field, props) // 根节点是不需要包FormItem的
return React.createElement(
FormConsumer,
Expand All @@ -382,7 +391,7 @@ registerFieldMiddleware(Field => {
label: schema.title,
noMinHeight: schema.type === 'object' && !schema['x-component'],
isTableColItem: isTableColItem(
path.slice(0, path.length - 2),
schemaPath.slice(0, schemaPath.length - 2),
getSchema
),
type: schema['x-component'] || schema['type'],
Expand Down

0 comments on commit 60e0917

Please sign in to comment.