👑 [需求]Proform 的水平布局,按钮位置无法控制,也没有栅格布局
🥰 需求描述
当前Proform中在使用水平布局的时候,因为表单项都走了栅格,但是按钮没有使用栅格,会导致按钮在行首,位置无法优雅控制。
🧐 解决方案
提供API控制按钮位置,或者按钮也纳入栅格中来。
🚑 其他信息

以下的 Issues 可能会帮助到你 / The following issues may help you
- [#2798][proform👑 [需求]][85%]
TAutomatically replying with ChatGPT can be attempted, but it cannot be guaranteed to be completely accurate and may not fully address all issues. Please feel free to reply if you have any further questions or concerns. 此回复基于 ChatGPT 自动生成,可以尝试下方案,官方人员会在一定时间后继续继续处理。
针对该需求,我建议通过以下方式来实现:
-
在 Proform 组件中增加一个属性
buttonSpan,用于控制按钮所占用的栅格数。默认值可以设置为 24。 -
在 Proform 组件中,为按钮添加一个 Col 组件,使其也可以被控制栅格宽度。
下面是代码示例:
import { Form, Input, Button, Col } from 'antd';
const ProForm = ({ buttonSpan = 24, ...props }) => {
return (
<Form {...props}>
<Form.Item label="姓名" name="name">
<Input />
</Form.Item>
<Form.Item label="邮箱" name="email">
<Input />
</Form.Item>
<Form.Item label="公司" name="company">
<Input />
</Form.Item>
<Col span={buttonSpan}>
<Button type="primary" htmlType="submit">
提交
</Button>
</Col>
</Form>
);
};
使用时,你可以通过传入 buttonSpan 属性来控制按钮所占用的栅格宽度。
<ProForm buttonSpan={8} />
此外,Ant Design 官方文档也提供了相关的文档,可以供您参考:
支持了 colProps,可以试试了。
Proform 更推荐错落有致,不是很推荐格栅布局
请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢
请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢
同问....
请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢
可以这样:(注意这里的className, 我使用了taiwind css)
<ProForm<Params>
className="p-1"
initialValues={initialValues}
onFinish={onFinish}
submitter={false}
>
<div className="flex flex-row">
<ProFormDatePicker name="date" label={false} fieldProps={{ format: "YYYY-MM-DD" }} style={{ marginRight: '10px' }} />
<ProFormText name="coverage_status" label={false} style={{ marginRight: '10px' }} />
<ProFormText name="name" label={false} />
<Button type="primary" htmlType="submit">
提交
</Button>
</div>
</ProForm>