Files
Saturnino Abril 402808622c [MM-10519] Remove channel from MoreChannels whenever a channel is converted form public to private (#1218)
* remove channel from MoreChannels whenever a channel is converted from public to private
* updated handling "updated channel" ws event and also other comments
* updated
* dispatch channel_id after receiving channel_convert event
* updated mattermost-redux to include related change
* move mapStateToProps on top of mapDispatchToProps
2018-06-04 23:18:00 +08:00

91 lines
2.3 KiB
React

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
// A component that can be used to make controlled inputs that function properly in certain
// environments (ie. IE11) where typing quickly would sometimes miss inputs
export default class QuickInput extends React.PureComponent {
static propTypes = {
/**
* Whether to delay updating the value of the textbox from props. Should only be used
* on textboxes that to properly compose CJK characters as the user types.
*/
delayInputUpdate: PropTypes.bool,
/**
* An optional React component that will be used instead of an HTML input when rendering
*/
inputComponent: PropTypes.func,
/**
* The string value displayed in this input
*/
value: PropTypes.string.isRequired,
};
static defaultProps = {
delayInputUpdate: false,
value: '',
};
componentDidUpdate(prevProps) {
if (prevProps.value !== this.props.value) {
if (this.props.delayInputUpdate) {
requestAnimationFrame(this.updateInputFromProps);
} else {
this.updateInputFromProps();
}
}
}
updateInputFromProps = () => {
if (!this.input || this.input.value === this.props.value) {
return;
}
this.input.value = this.props.value;
}
get value() {
return this.input.value;
}
set value(value) {
this.input.value = value;
}
focus() {
this.input.focus();
}
blur() {
this.input.blur();
}
getInput = () => {
return this.input;
};
setInput = (input) => {
this.input = input;
}
render() {
const {value, inputComponent, ...props} = this.props;
Reflect.deleteProperty(props, 'delayInputUpdate');
return React.createElement(
inputComponent || 'input',
{
...props,
ref: this.setInput,
defaultValue: value, // Only set the defaultValue since the real one will be updated using componentDidUpdate
}
);
}
}