Disabled keyboard focus code changes on mobile

Этот коммит содержится в:
hmhealey
2016-02-05 12:22:39 -05:00
родитель 4fabe574fa
Коммит d494283989
2 изменённых файлов: 21 добавлений и 8 удалений

Просмотреть файл

@@ -59,6 +59,7 @@ class CreateComment extends React.Component {
this.getFileCount = this.getFileCount.bind(this); this.getFileCount = this.getFileCount.bind(this);
this.handleResize = this.handleResize.bind(this); this.handleResize = this.handleResize.bind(this);
this.onPreferenceChange = this.onPreferenceChange.bind(this); this.onPreferenceChange = this.onPreferenceChange.bind(this);
this.focusTextbox = this.focusTextbox.bind(this);
PostStore.clearCommentDraftUploads(); PostStore.clearCommentDraftUploads();
@@ -76,7 +77,7 @@ class CreateComment extends React.Component {
PreferenceStore.addChangeListener(this.onPreferenceChange); PreferenceStore.addChangeListener(this.onPreferenceChange);
window.addEventListener('resize', this.handleResize); window.addEventListener('resize', this.handleResize);
this.refs.textbox.focus(); this.focusTextbox();
} }
componentWillUnmount() { componentWillUnmount() {
PreferenceStore.removeChangeListener(this.onPreferenceChange); PreferenceStore.removeChangeListener(this.onPreferenceChange);
@@ -99,7 +100,7 @@ class CreateComment extends React.Component {
} }
if (prevProps.rootId !== this.props.rootId) { if (prevProps.rootId !== this.props.rootId) {
this.refs.textbox.focus(); this.focusTextbox();
} }
} }
handleSubmit(e) { handleSubmit(e) {
@@ -226,7 +227,7 @@ class CreateComment extends React.Component {
} }
} }
handleUploadClick() { handleUploadClick() {
this.refs.textbox.focus(); this.focusTextbox();
} }
handleUploadStart(clientIds) { handleUploadStart(clientIds) {
let draft = PostStore.getCommentDraft(this.props.rootId); let draft = PostStore.getCommentDraft(this.props.rootId);
@@ -238,7 +239,7 @@ class CreateComment extends React.Component {
// this is a bit redundant with the code that sets focus when the file input is clicked, // this is a bit redundant with the code that sets focus when the file input is clicked,
// but this also resets the focus after a drag and drop // but this also resets the focus after a drag and drop
this.refs.textbox.focus(); this.focusTextbox();
} }
handleFileUploadComplete(filenames, clientIds) { handleFileUploadComplete(filenames, clientIds) {
let draft = PostStore.getCommentDraft(this.props.rootId); let draft = PostStore.getCommentDraft(this.props.rootId);
@@ -306,6 +307,11 @@ class CreateComment extends React.Component {
getFileCount() { getFileCount() {
return this.state.previews.length + this.state.uploadsInProgress.length; return this.state.previews.length + this.state.uploadsInProgress.length;
} }
focusTextbox() {
if (!Utils.isMobile()) {
this.refs.textbox.focus();
}
}
render() { render() {
let serverError = null; let serverError = null;
if (this.state.serverError) { if (this.state.serverError) {

Просмотреть файл

@@ -63,6 +63,7 @@ class CreatePost extends React.Component {
this.getFileCount = this.getFileCount.bind(this); this.getFileCount = this.getFileCount.bind(this);
this.handleKeyDown = this.handleKeyDown.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this);
this.sendMessage = this.sendMessage.bind(this); this.sendMessage = this.sendMessage.bind(this);
this.focusTextbox = this.focusTextbox.bind(this);
PostStore.clearDraftUploads(); PostStore.clearDraftUploads();
@@ -193,6 +194,11 @@ class CreatePost extends React.Component {
} }
); );
} }
focusTextbox() {
if (!Utils.isMobile()) {
this.refs.textbox.focus();
}
}
postMsgKeyPress(e) { postMsgKeyPress(e) {
if (this.state.ctrlSend && e.ctrlKey || !this.state.ctrlSend) { if (this.state.ctrlSend && e.ctrlKey || !this.state.ctrlSend) {
if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) {
@@ -216,7 +222,7 @@ class CreatePost extends React.Component {
PostStore.storeCurrentDraft(draft); PostStore.storeCurrentDraft(draft);
} }
handleUploadClick() { handleUploadClick() {
this.refs.textbox.focus(); this.focusTextbox();
} }
handleUploadStart(clientIds, channelId) { handleUploadStart(clientIds, channelId) {
const draft = PostStore.getDraft(channelId); const draft = PostStore.getDraft(channelId);
@@ -228,7 +234,7 @@ class CreatePost extends React.Component {
// this is a bit redundant with the code that sets focus when the file input is clicked, // this is a bit redundant with the code that sets focus when the file input is clicked,
// but this also resets the focus after a drag and drop // but this also resets the focus after a drag and drop
this.refs.textbox.focus(); this.focusTextbox();
} }
handleFileUploadComplete(filenames, clientIds, channelId) { handleFileUploadComplete(filenames, clientIds, channelId) {
const draft = PostStore.getDraft(channelId); const draft = PostStore.getDraft(channelId);
@@ -305,11 +311,12 @@ class CreatePost extends React.Component {
componentDidMount() { componentDidMount() {
ChannelStore.addChangeListener(this.onChange); ChannelStore.addChangeListener(this.onChange);
PreferenceStore.addChangeListener(this.onPreferenceChange); PreferenceStore.addChangeListener(this.onPreferenceChange);
this.refs.textbox.focus();
this.focusTextbox();
} }
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (prevState.channelId !== this.state.channelId) { if (prevState.channelId !== this.state.channelId) {
this.refs.textbox.focus(); this.focusTextbox();
} }
} }
componentWillUnmount() { componentWillUnmount() {