]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10077 Right part navigation bar is inaccessible very small window
authorPascal Mugnier <pascal.mugnier@sonarsource.com>
Tue, 8 May 2018 09:30:10 +0000 (11:30 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 24 May 2018 18:20:47 +0000 (20:20 +0200)
server/sonar-web/src/main/js/components/nav/NavBar.tsx

index b25d89ed3020ec74163a7d4c3a2d245670d3fdbd..f8ab495a6220f194adf649b204e6782e5cbe7690 100644 (file)
@@ -19,6 +19,7 @@
  */
 import * as React from 'react';
 import * as classNames from 'classnames';
+import { throttle } from 'lodash';
 import './NavBar.css';
 
 interface Props {
@@ -29,15 +30,42 @@ interface Props {
   [prop: string]: any;
 }
 
-export default function NavBar({ children, className, height, notif, ...other }: Props) {
-  return (
-    <nav {...other} className={classNames('navbar', className)} style={{ height }}>
-      <div
-        className={classNames('navbar-inner', { 'navbar-inner-with-notif': notif != null })}
-        style={{ height }}>
-        <div className="navbar-limited clearfix">{children}</div>
-        {notif}
-      </div>
-    </nav>
-  );
+interface State {
+  left: number;
+}
+
+export default class NavBar extends React.PureComponent<Props, State> {
+  throttledFollowHorizontalScroll: (() => void);
+
+  constructor(props: Props) {
+    super(props);
+    this.state = { left: 0 };
+    this.throttledFollowHorizontalScroll = throttle(this.followHorizontalScroll, 10);
+  }
+
+  componentDidMount() {
+    document.addEventListener('scroll', this.throttledFollowHorizontalScroll);
+  }
+
+  componentWillUnmount() {
+    document.removeEventListener('scroll', this.throttledFollowHorizontalScroll);
+  }
+
+  followHorizontalScroll = () => {
+    this.setState({ left: -document.documentElement.scrollLeft });
+  };
+
+  render() {
+    const { children, className, height, notif, ...other } = this.props;
+    return (
+      <nav {...other} className={classNames('navbar', className)} style={{ height }}>
+        <div
+          className={classNames('navbar-inner', { 'navbar-inner-with-notif': notif != null })}
+          style={{ height, left: this.state.left }}>
+          <div className="navbar-limited clearfix">{children}</div>
+          {notif}
+        </div>
+      </nav>
+    );
+  }
 }