Skip to content

Commit

Permalink
Fixed the MM-34128 issue (mattermost#7750)
Browse files Browse the repository at this point in the history
Added the support to show clear button even if the input has no value in Quickinput component

Co-authored-by: Manoj <[email protected]>
  • Loading branch information
chetanyakan and manojmalik20 committed May 7, 2021
1 parent 8b35424 commit 66c7fb8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components/custom_status/custom_status_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const CustomStatusModal: React.FC<Props> = (props: Props) => {
inputComponent={MaxLengthInput}
value={text}
maxLength={Constants.CUSTOM_STATUS_TEXT_CHARACTER_LIMIT}
clearable={Boolean(isStatusSet)}
clearableWithoutValue={Boolean(isStatusSet)}
onClear={clearHandle}
className='form-control'
clearClassName='StatusModal__clear-container'
Expand Down
11 changes: 9 additions & 2 deletions components/quick_input/quick_input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export default class QuickInput extends React.PureComponent {
* Callback to handle the change event of the input
*/
onChange: PropTypes.func,

/**
* When true, and an onClear callback is defined, show an X on the input field even if
* the input is empty.
*/
clearableWithoutValue: PropTypes.bool,
};

static defaultProps = {
Expand Down Expand Up @@ -140,7 +146,7 @@ export default class QuickInput extends React.PureComponent {
</Tooltip>
);

const {value, inputComponent, clearable, clearClassName, tooltipPosition, ...props} = this.props;
const {value, inputComponent, clearable, clearClassName, tooltipPosition, clearableWithoutValue, ...props} = this.props;

Reflect.deleteProperty(props, 'delayInputUpdate');
Reflect.deleteProperty(props, 'onClear');
Expand All @@ -162,9 +168,10 @@ export default class QuickInput extends React.PureComponent {
},
);

const showClearButton = this.props.onClear && (clearableWithoutValue || (clearable && value));
return (<div>
{inputElement}
{clearable && value && this.props.onClear &&
{showClearButton &&
<div
className={classNames(clearClassName, 'input-clear visible')}
onMouseDown={this.onClear}
Expand Down

0 comments on commit 66c7fb8

Please sign in to comment.