From 68a8cdda012d09ee4fc87dda50c7da81f0b46f36 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 30 Apr 2020 20:49:11 +0800 Subject: [PATCH 1/2] :zap: Support Input.Password iconRender close #23778 close #23484 --- components/input/Password.tsx | 11 +++++++---- components/input/demo/password-input.md | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/components/input/Password.tsx b/components/input/Password.tsx index a1c4d8bb5fc7..490ce3713ce9 100644 --- a/components/input/Password.tsx +++ b/components/input/Password.tsx @@ -11,6 +11,7 @@ export interface PasswordProps extends InputProps { readonly inputPrefixCls?: string; readonly action?: string; visibilityToggle?: boolean; + iconRender?: (visible: boolean) => React.ReactNode; } export interface PasswordState { @@ -28,6 +29,7 @@ export default class Password extends React.Component (visible ? : ), }; state: PasswordState = { @@ -44,9 +46,10 @@ export default class Password extends React.Component { - const { action } = this.props; + const { action, iconRender = () => null } = this.props; + const { visible } = this.state; const iconTrigger = ActionMap[action!] || ''; - const icon = this.state.visible ? EyeOutlined : EyeInvisibleOutlined; + const icon = iconRender(visible); const iconProps = { [iconTrigger]: this.onVisibleChange, className: `${prefixCls}-icon`, @@ -62,7 +65,7 @@ export default class Password extends React.Component{icon}, iconProps); }; saveInput = (instance: Input) => { @@ -102,7 +105,7 @@ export default class Password extends React.Component, mountNode); +ReactDOM.render( + + + (visible ? : )} + /> + , + mountNode, +); ``` From b3fc7a69dd0c76a71cf7f0915fac50edfe04ea4a Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 30 Apr 2020 20:54:26 +0800 Subject: [PATCH 2/2] :white_check_mark: fix snapshot --- .../__tests__/__snapshots__/demo.test.js.snap | 118 +++++++++++++----- 1 file changed, 85 insertions(+), 33 deletions(-) diff --git a/components/input/__tests__/__snapshots__/demo.test.js.snap b/components/input/__tests__/__snapshots__/demo.test.js.snap index 3f9b93cecae1..1ab7b00c1bce 100644 --- a/components/input/__tests__/__snapshots__/demo.test.js.snap +++ b/components/input/__tests__/__snapshots__/demo.test.js.snap @@ -1899,45 +1899,97 @@ exports[`renders ./components/input/demo/group.md correctly 1`] = ` `; exports[`renders ./components/input/demo/password-input.md correctly 1`] = ` - - - - + - - - + + + + - - + +
+ + + + + + + + +
+ `; exports[`renders ./components/input/demo/presuffix.md correctly 1`] = `