Semantic-UI-React:Form.Field正在中断布局[已解决]

问题描述 投票:0回答:2

我正在创建新产品的表单中,我需要一行包含3个相等字段,但我无法使用React Semantic Ui到达那里。

如何使用react语义ui对3个相等的输入字段进行编码?

这就是我尝试过的:

import { Form, Input, Button, TextArea, Header, Icon } from "semantic-ui-react";

function CreateProduct() {
  return (
    <>
      <Header as="h2" block>
        <Icon name="add square" color="violet" />
        Cadastrar Produto
      </Header>
      <Form>
        <Form.Group widths="equal">
          <Form.Field
            control={Input}
            name="name"
            label="Nome"
            placeholder="Nome do Produto"
          />
          <Form.Field
            control={Input}
            name="price"
            label="Preço"
            placeholder="Preço"
            min="0.00"
            step="0.10"
            type="number"
          />
          <Form.Field
            control={Input}
            name="media"
            type="file"
            label="Imagem"
            accept="image/*"
            content="Escolha Imagem"
          />
        </Form.Group>
        <Form.Field
          control={TextArea}
          name="description"
          label="Descrição"
          placeholder="Descrição do Produto"
        />
        <Form.Field
          control={Button}
          inverted
          color="violet"
          icon="pencil alternate"
          content="Cadastrar"
          type="submit"
        />
      </Form>
    </>
  );
}

export default CreateProduct;

我得到的输出是:

Output view

是否看到第三个输入“ Imagem”?

似乎该字段未遵循Form.Group props widths ='equal'from semanctic-react-ui document

Ps:我是stackoverflow的新手,提出了第一个问题,希望能在这里为社区带来帮助。

感谢您考虑我的要求。

解决方案:我在Form.Field上添加了Fluid道具,并且效果很好。

javascript reactjs semantic-ui-react
2个回答
0
投票

由于file类型的内容,超出了此布局。也许您可以尝试这种方式来获得布局

import React, { Component } from "react";
import { Form, Input, Button, TextArea } from "semantic-ui-react";

class FormExample extends Component {
  fileInputRef = React.createRef();
  render() {
    return (
      <Form>
        <Form.Group widths="equal">
          <Form.Field
            control={Input}
            name="name"
            label="Nome"
            placeholder="Nome do Produto"
          />
          <Form.Field
            control={Input}
            name="price"
            label="Preço"
            placeholder="Preço"
            min="0.00"
            step="0.10"
            type="number"
          />
          <Form.Field>
            <label>Imagem</label>
            <Button
              style={{ width: "100%" }}
              content="Choose File"
              labelPosition="left"
              icon="file"
              onClick={() => this.fileInputRef.current.click()}
            />
            <input
              ref={this.fileInputRef}
              type="file"
              hidden
              onChange={this.fileChange}
            />
          </Form.Field>
        </Form.Group>
        <Form.Field
          control={TextArea}
          name="description"
          label="Descrição"
          placeholder="Descrição do Produto"
        />
        <Form.Field
          control={Button}
          inverted
          color="violet"
          icon="pencil alternate"
          content="Cadastrar"
          type="submit"
        />
      </Form>
    );
  }
}

export default FormExample;

演示https://codesandbox.io/s/zen-frost-9ihqw(调整全屏显示尺寸)


0
投票

[我发现了一个很好的解决方案,只需在第二个上添加“ Fluid”道具。

<Form.Field
  fluid
  control={Input}
  name="price"
  label="Preço"
  placeholder="Preço"
  min="0.00"
  step="0.10"
  type="number"
/>

© www.soinside.com 2019 - 2024. All rights reserved.