Skip to content

Button组件被渲染为View,而无法与Form交互 #3418

@liudichen

Description

@liudichen

NutUI React 包名

@nutui/nutui-react-taro

NutUI React 版本号

3.0.19-cpp.23

平台

weapp, h5

重现链接

https://github.com/liudichen/nutui-bug

重现步骤

import { Button, Form, Input } from "@nutui/nutui-react-taro";

export const PasswordLogin = () => {
  return (
    <>
      <Form
        divider
        labelPosition="left"
        starPosition="right"
        onFinish={console.log}
        onFinishFailed={console.log}
        footer={
            <Button nativeType="submit" type="primary">
              登录
            </Button>
        }
      >
        <Form.Item
          required
          name="codeOrMobile"
          label="账号"
          rules={[{ required: true, message: "此项为必填项" }]}
        >
          <Input type="text" placeholder="手机号" />
        </Form.Item>
        <Form.Item
          required
          name="password"
          label="密码"
          rules={[{ required: true, message: "此项为必填项" }]}
        >
          <Input type="password" placeholder="密码" />
        </Form.Item>
      </Form>
    </>
  );
};

期望的结果是什么?

Button组件渲染为小程序button后h5 Button,并可以出发Form的提交操作

实际的结果是什么?

实际渲染为了View,无法与Form交互

环境信息

 "dependencies": {
    "@babel/runtime": "^7.28.6",
    "@nutui/icons-react-taro": "3.0.2-cpp.3.beta.4",
    "@nutui/nutui-react-taro": "3.0.19-cpp.23",
    "@tarojs/components": "4.1.9",
    "@tarojs/helper": "4.1.9",
    "@tarojs/plugin-framework-react": "4.1.9",
    "@tarojs/plugin-html": "4.1.9",
    "@tarojs/plugin-platform-alipay": "4.1.9",
    "@tarojs/plugin-platform-h5": "4.1.9",
    "@tarojs/plugin-platform-jd": "4.1.9",
    "@tarojs/plugin-platform-qq": "4.1.9",
    "@tarojs/plugin-platform-swan": "4.1.9",
    "@tarojs/plugin-platform-tt": "4.1.9",
    "@tarojs/plugin-platform-weapp": "4.1.9",
    "@tarojs/react": "4.1.9",
    "@tarojs/runtime": "4.1.9",
    "@tarojs/shared": "4.1.9",
    "@tarojs/taro": "4.1.9",
    "react": "^18.3.1",
    "react-dom": "^18.3.1"
  },

其他补充信息

我注意到npm下载的软件包,构建的button组件tarobutton部分被注释掉了( // <TaroButton),源代码里是没被注释的

node_modules\@nutui\nutui-react-taro\dist\es\packages\button\button.js:

export var Button = /*#__PURE__*/ React.forwardRef(function(props, ref) {
    var _ref = _object_spread({}, defaultProps, props), color = _ref.color, shape = _ref.shape, fill = _ref.fill, loading = _ref.loading, disabled = _ref.disabled, type = _ref.type, size = _ref.size, block = _ref.block, icon = _ref.icon, rightIcon = _ref.rightIcon, children = _ref.children, className = _ref.className, style = _ref.style, // formType,
    nativeType = _ref.nativeType, onClick = _ref.onClick, rest = _object_without_properties(_ref, [
        "color",
        "shape",
        "fill",
        "loading",
        "disabled",
        "type",
        "size",
        "block",
        "icon",
        "rightIcon",
        "children",
        "className",
        "style",
        "nativeType",
        "onClick"
    ]);
    var getStyle = useMemo(function() {
        var style = {};
        if (color) {
            if (props.fill === 'outline' || props.fill === 'dashed') {
                style.color = color;
                if (!(color === null || color === void 0 ? void 0 : color.includes('gradient'))) {
                    style.borderColor = color;
                }
            } else {
                style.color = '#fff';
                if (harmony()) {
                    style.backgroundColor = color;
                }
                style.background = color;
                style.borderColor = 'transparent';
            }
        }
        return style;
    }, [
        color,
        props.fill
    ]);
    var getContStyle = useMemo(function() {
        var style = {};
        if (props.color) {
            if (props.fill === 'outline' || props.fill === 'dashed') {
                style.color = color;
            } else {
                style.color = '#fff';
                style.background = 'transparent';
                style.borderColor = 'transparent';
            }
        }
        return style;
    }, [
        color,
        props.fill,
        props.color
    ]);
    var handleClick = useCallback(function(e) {
        if (!loading && !disabled && onClick) {
            onClick(e);
        }
    }, [
        loading,
        disabled,
        onClick
    ]);
    var _obj;
    var buttonClassNames = classNames(prefixCls, "".concat(prefixCls, "-").concat(type), (_obj = {}, _define_property(_obj, "".concat(prefixCls, "-").concat(type, "-solid"), type === 'primary' && !props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(fill), props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(type, "-").concat(fill), props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(size), size), _define_property(_obj, "".concat(prefixCls, "-").concat(shape), shape), _define_property(_obj, "".concat(prefixCls, "-").concat(shape, "-").concat(size), shape && size), _define_property(_obj, "".concat(prefixCls, "-block"), block), _define_property(_obj, "".concat(prefixCls, "-disabled"), disabled || loading), _define_property(_obj, "".concat(prefixCls, "-").concat(type).concat(props.fill ? "-".concat(fill) : '', "-disabled"), disabled || loading), _define_property(_obj, "".concat(prefixCls, "-loading"), loading), _define_property(_obj, "".concat(prefixCls, "-icononly"), !children), _obj), className);
    // if (getEnv() === 'WEB') {
    //   ;(rest as any).type = formType
    // }
    return (
        // eslint-disable-next-line @typescript-eslint/ban-ts-comment
        // @ts-ignore
        // eslint-disable-next-line react/button-has-type
        // <TaroButton
        /*#__PURE__*/_ (React.createElement(View, _object_spread_props(_object_spread({}, rest), {
            ref: ref,
            // formType={formType || nativeType}
            className: buttonClassNames,
            style: _object_spread({}, getStyle, style),
            onClick: function(e) {
                return handleClick(e);
            }
        }), /*#__PURE__*/ React.createElement(View, {
            className: "nut-button-wrap"
        }, loading && /*#__PURE__*/ React.createElement(Loading, {
            className: "nut-icon-loading"
        }), !loading && icon, children && /*#__PURE__*/ React.createElement(View, {
            className: "nut-button-children nut-button-".concat(size, "-children nut-button-").concat(type, "-children ").concat(!(props.fill || disabled || loading) ? '' : "nut-button-".concat(type).concat(props.fill ? "-".concat(fill) : '').concat(disabled || loading ? '-disabled' : '')).concat(icon || loading ? " nut-button-text" : '').concat(rightIcon ? ' nut-button-text-right' : ''),
            style: harmony() ? getContStyle : {}
        }, children), rightIcon)))
    );
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions