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

feat(input): 优化 clearable 按钮显示逻辑 #1415

Merged
merged 4 commits into from
Aug 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
31 changes: 27 additions & 4 deletions src/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
mouseEvent(v: boolean) {
this.isHover = v;
},
renderIcon(h: CreateElement, icon: string | Function | undefined, iconType: 'prefix-icon' | 'suffix-icon') {
renderIcon(
h: CreateElement,
icon: string | Function | undefined,
iconType: 'prefix-icon' | 'suffix-icon' | 'password-icon',
) {
if (typeof icon === 'function') {
return icon(h);
}
Expand Down Expand Up @@ -320,6 +324,7 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input

const prefixIcon = this.renderIcon(h, this.prefixIcon, 'prefix-icon');
let suffixIcon = this.renderIcon(h, this.suffixIcon, 'suffix-icon');
let passwordIcon = this.renderIcon(h, undefined, 'password-icon');

const label = renderTNodeJSX(this, 'label');
const suffix = renderTNodeJSX(this, 'suffix');
Expand All @@ -342,9 +347,16 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
}

if (this.showClear) {
suffixIcon = (
<CloseCircleFilledIcon class={`${this.componentName}__suffix-clear`} nativeOnClick={this.emitClear} />
);
// 如果类型为 password 则使用 passwordIcon 显示 clear
if (this.type === 'password') {
passwordIcon = (
<CloseCircleFilledIcon class={`${this.componentName}__suffix-clear`} nativeOnClick={this.emitClear} />
);
} else {
suffixIcon = (
<CloseCircleFilledIcon class={`${this.componentName}__suffix-clear`} nativeOnClick={this.emitClear} />
);
}
}

const classes = [
Expand Down Expand Up @@ -385,6 +397,17 @@ export default mixins(getConfigReceiverMixins<InputInstance, InputConfig>('input
</span>
)}
{suffixContent}
{passwordIcon ? (
<span
class={[
`${this.componentName}__suffix`,
`${this.componentName}__suffix-icon`,
`${this.componentName}__clear`,
]}
>
{passwordIcon}
</span>
) : null}
{suffixIcon ? (
<span
class={[
Expand Down