From 00d5a8dc3983b1b5911c7279394ebdac564a798e Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 24 Aug 2018 17:27:09 +0300 Subject: scroll fixes for mobile --- vnext/src/components/MessageInput.js | 11 +++++++---- vnext/src/components/Thread.js | 2 ++ vnext/src/components/__tests__/MessageInput-test.js | 8 ++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'vnext') diff --git a/vnext/src/components/MessageInput.js b/vnext/src/components/MessageInput.js index 4fea2b57..4b3a0fd4 100644 --- a/vnext/src/components/MessageInput.js +++ b/vnext/src/components/MessageInput.js @@ -46,7 +46,10 @@ export default class MessageInput extends React.Component { } componentDidMount() { - this.textarea.current.focus(); + const isMobile = window.matchMedia('only screen and (max-width: 850px)'); + if (!isMobile.matches) { + this.textarea.current.focus(); + } } textChanged = (event) => { this.setState({ @@ -77,8 +80,8 @@ export default class MessageInput extends React.Component {
diff --git a/vnext/src/components/Thread.js b/vnext/src/components/Thread.js index 7f8e515a..b426581d 100644 --- a/vnext/src/components/Thread.js +++ b/vnext/src/components/Thread.js @@ -31,6 +31,8 @@ export default class Thread extends React.Component { this.loadReplies(); } loadReplies() { + document.body.scrollTop = 0; + document.documentElement.scrollTop = 0; this.setState({ replies: [], loading: true }); const { mid } = this.props.match.params; let params = { diff --git a/vnext/src/components/__tests__/MessageInput-test.js b/vnext/src/components/__tests__/MessageInput-test.js index 65ec383d..1cf89ebf 100644 --- a/vnext/src/components/__tests__/MessageInput-test.js +++ b/vnext/src/components/__tests__/MessageInput-test.js @@ -14,6 +14,14 @@ const testMessage = { timestamp: new Date().toISOString() }; +window.matchMedia = window.matchMedia || function() { + return { + matches : false, + addListener : function() {}, + removeListener: function() {} + }; +}; + it('Gives immediate focus on to textarea on load', () => { const wrapper = mount(