From 0017d9c9fe0c56cb50cc9a4b240795e9bceca088 Mon Sep 17 00:00:00 2001 From: RUNZE LU <36724300+lurunze1226@users.noreply.github.com> Date: Wed, 29 Jun 2022 20:35:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20InputPassword=E7=BB=84=E4=BB=B6revealPas?= =?UTF-8?q?sword=E5=B1=9E=E6=80=A7=E6=B2=A1=E6=9C=89update=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#4738)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-CN/components/form/input-password.md | 23 ++++++++++++++++++++ src/renderers/Form/InputText.tsx | 10 ++++++++- src/renderers/Form/Item.tsx | 3 ++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/zh-CN/components/form/input-password.md b/docs/zh-CN/components/form/input-password.md index 33e0ad093..f6594a1fd 100644 --- a/docs/zh-CN/components/form/input-password.md +++ b/docs/zh-CN/components/form/input-password.md @@ -24,10 +24,33 @@ order: 35 } ``` +## 配置密码显/隐藏 + +`revealPassword`属性可以设置是否展示密码显/隐按钮,默认为`true`。 + +```schema: scope="body" +{ + "type": "form", + "api": "/api/mock2/form/saveForm", + "body": [ + { + "type": "input-password", + "name": "password", + "label": "密码", + "revealPassword": false + } + ] +} +``` + ## 属性表 请参考[输入框](./input-text) +| 属性名 | 类型 | 默认值 | 说明 | +| -------------- | --------- | ------ | --------------------- | +| revealPassword | `boolean` | `true` | 是否展示密码显/隐按钮 | + ## 事件表 请参考[输入框](./input-text) diff --git a/src/renderers/Form/InputText.tsx b/src/renderers/Form/InputText.tsx index 2110c8224..05e94f0f6 100644 --- a/src/renderers/Form/InputText.tsx +++ b/src/renderers/Form/InputText.tsx @@ -220,6 +220,10 @@ export default class TextControl extends React.PureComponent< : this.valueToString(props.value) }); } + if (prevProps.revealPassword !== props.revealPassword) { + /** 隐藏按钮的同时将密码设置为隐藏态 */ + !props.revealPassword && this.setState({revealPassword: false}); + } } componentWillUnmount() { @@ -835,7 +839,11 @@ export default class TextControl extends React.PureComponent< step={step} onChange={this.handleNormalInputChange} value={this.valueToString(value)} - className={cx(type === 'password' && revealPassword && 'TextControl-input-password')} + className={cx( + type === 'password' && + revealPassword && + 'TextControl-input-password' + )} /> {clearable && !disabled && !readOnly && value ? ( diff --git a/src/renderers/Form/Item.tsx b/src/renderers/Form/Item.tsx index 49793ef8d..b5c0107bd 100644 --- a/src/renderers/Form/Item.tsx +++ b/src/renderers/Form/Item.tsx @@ -1184,7 +1184,8 @@ export const detectProps = [ 'minLength', 'maxLength', 'embed', - 'displayMode' + 'displayMode', + 'revealPassword' ]; export function asFormItem(config: Omit) {