Skip to content

Commit

Permalink
Hide clear button when input is disabled or readonly (#1513)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpylua authored Oct 28, 2020
1 parent fa19ecc commit 57f797e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/zent/src/input/InputCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const InputCore = React.forwardRef<
onCompositionEndProp
);

// No clear button when input is disabled or readonly
const showClearIcon =
showClear && valueProp && !otherProps.disabled && !otherProps.readOnly;

return (
<>
{addonBefore && (
Expand All @@ -62,7 +66,7 @@ export const InputCore = React.forwardRef<
onCompositionStart={onCompositionStart}
onCompositionEnd={onCompositionEnd}
/>
{showClear && valueProp && (
{showClearIcon && (
<Icon
className="zent-input-close"
type="close-circle"
Expand Down
2 changes: 2 additions & 0 deletions packages/zent/src/input/demos/disabled.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { Input } from 'zent';
ReactDOM.render(
<div>
<Input value="Blah" disabled />
<Input value="Blah" disabled showClear />
<Input value="Blah" readOnly showClear />
<Input icon="search" disabled />
<Input value="42" disabled addonBefore="$" />
<Input value="42" readOnly addonAfter="{i18n.days}" />
Expand Down

0 comments on commit 57f797e

Please sign in to comment.