Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#1270) : 解决 AtButton formType='submit' 微信小程序下不能触发事件 #1270 #1533

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions packages/taro-ui/src/components/button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import classNames from 'classnames'
import PropTypes, { InferProps } from 'prop-types'
import React from 'react'
import { Button, Form, View } from '@tarojs/components'
import { Button, View } from '@tarojs/components'
import { ButtonProps } from '@tarojs/components/types/Button'
import { BaseEventOrig, CommonEvent } from '@tarojs/components/types/common'
import Taro from '@tarojs/taro'
Expand Down Expand Up @@ -62,30 +62,6 @@ export default class AtButton extends React.Component<
this.props.onOpenSetting && this.props.onOpenSetting(event)
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developers.weixin.qq.com/miniprogram/dev/component/form.html

微信端需加上 behaviors = ['wx://form-field']

private onSumit(event: CommonEvent): void {
if (this.state.isWEAPP || this.state.isWEB) {
// TODO: 3.0 this.$scope
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
this.$scope.triggerEvent('submit', event.detail, {
bubbles: true,
composed: true
})
}
}

private onReset(event: CommonEvent): void {
if (this.state.isWEAPP || this.state.isWEB) {
// TODO: 3.0 this.$scope
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
this.$scope.triggerEvent('reset', event.detail, {
bubbles: true,
composed: true
})
}
}

public render(): JSX.Element {
const {
size = 'normal',
Expand Down Expand Up @@ -162,14 +138,7 @@ export default class AtButton extends React.Component<
onClick={this.onClick.bind(this)}
>
{isWEB && !disabled && webButton}
{isWEAPP && !disabled && (
<Form
onSubmit={this.onSumit.bind(this)}
onReset={this.onReset.bind(this)}
>
{button}
</Form>
)}
{isWEAPP && !disabled && button}
{isALIPAY && !disabled && button}
{loadingComponent}
<View className='at-button__text'>{this.props.children}</View>
Expand Down