pro-components icon indicating copy to clipboard operation
pro-components copied to clipboard

👑 [需求]Proform 的水平布局,按钮位置无法控制,也没有栅格布局

Open wangchun0020 opened this issue 5 years ago • 6 comments

🥰 需求描述

当前Proform中在使用水平布局的时候,因为表单项都走了栅格,但是按钮没有使用栅格,会导致按钮在行首,位置无法优雅控制。

🧐 解决方案

提供API控制按钮位置,或者按钮也纳入栅格中来。

🚑 其他信息

image

wangchun0020 avatar Jun 29 '21 07:06 wangchun0020

以下的 Issues 可能会帮助到你 / The following issues may help you

  • [#2798][proform👑 [需求]][85%]

github-actions[bot] avatar Jun 29 '21 07:06 github-actions[bot]

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 自动生成,可以尝试下方案,官方人员会在一定时间后继续继续处理。

针对该需求,我建议通过以下方式来实现:

  1. 在 Proform 组件中增加一个属性 buttonSpan,用于控制按钮所占用的栅格数。默认值可以设置为 24。

  2. 在 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 官方文档也提供了相关的文档,可以供您参考:

chenshuai2144 avatar Mar 07 '23 02:03 chenshuai2144

支持了 colProps,可以试试了。

Proform 更推荐错落有致,不是很推荐格栅布局

chenshuai2144 avatar Mar 18 '23 13:03 chenshuai2144

请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢

Twinkle123321 avatar Apr 25 '23 07:04 Twinkle123321

请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢

同问....

ElsaOOo avatar Jul 06 '23 08:07 ElsaOOo

请问,如果想要按钮位置可以和文字在同一行应该怎么操作呢

可以这样:(注意这里的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>

ahuigo avatar Oct 16 '23 08:10 ahuigo